public class T {
static class t1 {
public int i = 5;
public int printA() {
return i;
}
}
static class t2 extends t1 {
public int i = 100;
public int printB() {
return i;
}
public void printC() {
{
System.out.println(super.i);
}
}
}
public static void main(String... args) {
t1 t = new t1();
t2 tt = new t2();
tt.printC(); //5
System.out.println(tt.printB()); //100
System.out.println(t.printA()); //5
System.out.println(tt.printA()); //5 不明白这里为啥是5而不是100?
t1 ttt = (t1) tt;
System.out.println(ttt.printA());//5
}
}
解决方案 »
- 帮我看看jdbc数据库查询怎么不能把结果存到集合
- 使用数据库连接池方式编码的时候为什么要close()
- java 循环串口 内存一直增加
- 单例有什么好处和坏处?STRUTS的ACTION是单例的吗
- 函数中嵌套类的问题
- 写了一个类似php中的explode的类,通过了编译,但在执行时错误,帮忙看一下!up有分!
- 为什么有在javac ItemBean.java时总报错,说:不能解析符号类DAO,DAOException
- 请问各位大侠那里能下到jdbcdriver for access?
- 我的Applet在IE中提示找不到类
- 新手求解:模拟一个trim功能一致的方法。去除字符串两端的空白
- for( : )的问题
- <xsd:element saw-name:hello="world"/>如何解析?
public class T {
static class t1 {
public int i = 5;
public int printA() {
System.out.println("t1.printA()");
return i;
}
}
static class t2 extends t1 {
public int i = 100;
public int printB() {
System.out.println("t2.printA()");
return i;
}
public void printC() {
{
System.out.println(super.i);
}
}
}
public static void main(String... args) {
t1 t = new t1();
t2 tt = new t2();
tt.printC(); //
System.out.println(tt.printB()); //
System.out.println(t.printA()); //
System.out.println(tt.printA()); //
t1 ttt = (t1) tt;
System.out.println(ttt.printA());//
}
} 结果是这样的,现在能理解了吧?
5
t2.printA()
100
t1.printA()
5
t1.printA()
5
t1.printA()
5