public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println("The Blacks! ver.1.1");
father f1 = new father();
f1.show();
f1.name(); f1.age();
mother m1 = new mother();
m1.name(); m1.age();
son s1 = new son();
s1.children();
s1.name(); s1.age();
daughter d1 = new daughter();
d1.children();
d1.name(); d1.age();
}
}
interface people {
void name();
void age();
}
class father
implements people {
private String fatherhaircolor = "yellow";
public String getfatherHaircolor() {
return fatherhaircolor;
}
public String familyname() {
String familyname = "Black";
return familyname ;
}
public void age() {
System.out.println("I am 30 years old.");
}
public void name() {
System.out.println("My name is Jack,Jack"+" "+this.familyname());
}
public void show() {
System.out.println("Ah,hello.");
}
}
class mother extends father{
private String motherhaircolor = "black";
public String getmotherhaircolor() {
return motherhaircolor;
}
public mother () {
System.out.println("Ya ha lo!!");
}
public void age() {
System.out.println("I am 27 years old.");
}
public void name() {
System.out.println("My name is Jenny,Jenny"+" "+this.familyname());
}
}
abstract class mychildren extends mother{
abstract void children();
}
class son extends mychildren{
public void show() {
System.out.println("Hi!");
}
public void children() {
System.out.println("I have "+this.getmotherhaircolor()+" hair.");
}
public void name() {
System.out.println("My name is Tom,Tom"+" "+this.familyname());
}
public void age() {
System.out.println("I am 6 years old.");
}
}
class daughter extends mychildren{
public daughter() {
System.out.println("Hh,hello...");
}
public void children() {
System.out.println("I have "+this.getfatherHaircolor()+" hair.");
}
public void name() {
System.out.println("My name is Penny,Penny"+" "+this.familyname());
}
public void age() {
System.out.println("I am 6 years old too.");
}
}
运行结果:
The Blacks! ver.1.1
Ah,hello.
My name is Jack,Jack Black
I am 30 years old.
Ya ha lo!!
My name is Jenny,Jenny Black
I am 27 years old.
Ya ha lo!!
I have black hair.
My name is Tom,Tom Black
I am 6 years old.
Ya ha lo!!
Hh,hello...
I have yellow hair.
My name is Penny,Penny Black
I am 6 years old too.