class Fu
{
public void show()
{
System.out.println("fu show");
}
public static void test() {
System.out.println("fu test");
}
}
class Zi extends Fu
{
private String name = "刘亦菲";
public void method()
{
System.out.println("zi method");
}
public void show()
{
System.out.println("zi show");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/*
这种写法,不是重写。
public int show()
{
System.out.println("zi show");
return 10;
}
*/
}
class ExtendsDemo4
{
final String name = "林青霞";
final int age = 26;
final Zi zi = new Zi();
public static void main(String[] args)
{
/*
//创建对象
Fu f = new Fu();
f.show();
System.out.println("------");
//创建对象
Zi z = new Zi();
z.show();
z.method();
*/
ExtendsDemo4 ex = new ExtendsDemo4();
System.out.println(ex.zi.getName());
// ex.zi = new Zi();
ex.zi.setName("林青霞");
System.out.println(ex.zi.getName());
}
}
|
|