Java中引用,造型等问题解析
文章作者 100test 发表时间 2008:03:18 15:08:28
来源 100Test.Com百考试题网
或许大家java的多态问题,对上溯,下溯造型有了一定的概念,对protected和private大家想必也很清楚,但是,这几个个结合在一起,往往令人产生很多困惑,在这里,我举一个例子,大家或许会发觉这篇文章对你来说还是很有意义的:
例子一共有两个class. 可能出现困惑的地方我都会在后面一一解释.A是父类,B继承A,并且实现了protectedTest(Object obj)方法.如下面所示:
B.java的源代码:
package cn.org.matrix.test.
import cn.org.matrix.test.A.
/**
*
Title: protect, private and upcasting
*
Description: email:[email protected]
*
Copyright: Matrix Copyright (c) 2003
*
Company: Matrix.org.cn
* @author chris
* @version 1.0,who use this example pls remain the declare
*/
public class B extends A
{
protected int protectedb = 0.
protected int protectedab = 0.
protected void protectedTest(Object obj)
{
System.out.println("in B.protectedTest(Object):" obj).
}
}
A.java的源代码:
package cn.org.matrix.test.
import cn.org.matrix.test.B.
/**
*
Title: protect, private and upcasting
*
Description: email:[email protected]
*
Copyright: Matrix Copyright (c) 2003
*
Company: Matrix.org.cn
* @author chris
* @version 1.0,who use this example pls remain the declare
*/