class Grandfather
{
String color= "Grandfather颜色";
}
class Father extends Grandfather
{
//String color= "Father颜色";
}
class Son extends Father
{
String color= "Son颜色";
String getSuperColor()
{
return super.color;
}
public static void main(String[] args)
{
//创建一个Apple对象
Son s = new Son();
//调用getSuper()方法获取Apple对象关联的super引用
Grandfather g = s;
Father f=s;
//判断a和f的关系
System.out.println("s.color:" +s.color);
System.out.println("f.color:" +f.color);
System.out.println("g.color:" +g.color);
System.out.println("s.getSuperColor():" + s.getSuperColor());
//System.out.println("f.getSuperColor():" + f.getSuperColor());
}
}
/*
s.color:Son颜色
f.color:Grandfather颜色
g.color:Grandfather颜色
s.getSuperColor():Grandfather颜色
请按任意键继续. . .
*/
return super.color;
最新推荐文章于 2023-06-23 12:30:00 发布