写出三个代码大家看下
class Father
{
int num=1;
}
class Son extends Father
{
int num=3;
void show()
{ num=2;
System.out.println(super.num);
}
}
class StringTest
{
public static void main(String[] args)
{
Son s=new Son();
s.show();
}
}
结果为1
class Father
{
int num=1;
}
class Son extends Father
{
//int num=3;
void show()
{ num=2;
System.out.println(super.num);
}
}
class StringTest
{
public static void main(String[] args)
{
Son s=new Son();
s.show();
}
}
结果为2
class Father
{
int num=1;
}
class Son extends Father
{
//int num=3;
void show()
{ //num=2;
System.out.println(this.num);
}
}
class StringTest
{
public static void main(String[] args)
{
Son s=new Son();
s.show();
}
}
结果为1 |