public class XiaoHong {
public static void main(String[] args) {
Father father = new Father("male");
Mother mother = new Mother("female");
father.jobA();
father.jobB();
mother.jobC();
mother.jobD();
Person xiaoHong = new Person("female", father, mother);
System.out.println("小红 is a " + xiaoHong.sex);
}
}
class Person {
String sex;
public Person(String sex, Object Father, Object Mother) {
this.sex = sex;
}
public Person(String sex) {
this.sex = sex;
}
}
class Mother extends Person implements JobC, JobD {
public Mother(String sex) {
super(sex);
}
public void jobC() {
System.out.println("小红爸 works jobC");
}
public void jobD() {
System.out.println("小红爸 works jobD");
}
}
class Father extends Person implements JobA, JobB {
public Father(String sex) {
super(sex);
}
public void jobA() {
System.out.println("小红妈 works jobA");
}
public void jobB() {
System.out.println("小红妈 works jobB");
}
}
interface JobA {
public void jobA();
}
interface JobB {
public void jobB();
}
interface JobC {
public void jobC();
}
interface JobD {
public void jobD();
}
|
-
1.jpg
(51.41 KB, 下载次数: 6)
|