本帖最后由 Lex 于 2014-5-31 16:51 编辑
public class Extend1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Begin b = new Begin();
D d = b.getCar();
d.show();
}
}
class DuoTai{
String str = "I am lost!";
public void nice(){
System.out.println("I will");
}
}
interface D{
public abstract void show();
}
class Begin extends DuoTai{
String str = "haha";
private class Car extends DuoTai implements D{
public void show(){
System.out.println("oh,my God!");
System.out.println(str);
}
}
public D getCar(){
return new Car();
}
}
为什么调用show()方法,输出str是继承的str,而不是优先外部类的str,代码在内存里执行的先后顺序是怎样的? |
|