求助。。。
/*
class Fu
{
private int age;
}
class Zi extends Fu
{
public int show()
{
return age;
}
}
class Help
{
public static void main(String[] args)
{
Zi z = new Zi();
System.out.println(z.show());
}
}
//age 可以在 Fu 中访问 private
// return age;
这是不是就表示父类私有的内容子类拿不到呢?
*/
class Fu
{
private int age = 50;
public int show()
{
return age;
}
}
class Zi extends Fu
{
}
class Help
{
public static void main(String[] args)
{
Zi z = new Zi();
System.out.println(z.show());//50
}
}
/*
class Person
{
private int age;
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
}
class Student extends Person
{
//public void setAge(int age)
//{
// this.age = age;
//}
//public int getAge()
//{
// return age;
//}
//为什么在子类重新写一次会编译失败?没有覆盖的话又是怎么回事呢?
}
class Help
{
public static void main(String[] args)
{
Student z = new Student();
z.setAge(20);
System.out.println(z.getAge());//20
}
}
*/ |
|