public static void main(String
[] args
) {
vers
.show();
father f1
= new father();
f1
.setName("Jack");
f1
.setAge(30);
f1
.show();
f1
.showage();
mother m1
= new mother();
m1
.setName("Jenny");
m1
.setAge(27);
m1
.show();
children s1
= new son();
children d1
= new daughter();
if (s1 instanceof son
) {
s1
.setName("Tom");
s1
.setAge(4);
s1
.mychildren();
children
.like();
}
else {
d1
.setName("Penny");
d1
.setAge(5);
d1
.mychildren();
}
mimi c1
= new mimi();
c1
.show();
}
}
class vers{
static void show() {
System
.out
.println("The Black!ver.1.2");
System
.out
.println("更新日志");
System
.out
.println("新版本1.2,增加更新日志");
System
.out
.println("重写people,father,mother类,变量均私有化");
System
.out
.println("修改抽象类children和类son,类daughter关系,调用更改为多态");
System
.out
.println("增加animal接口和cat类,后续更新类mimi选择语句新功能");
}
}
class people{
private String name
;
private int age
;
public String
getName() {
return name
;
}
public void setName(String name
) {
this.name
= name
;
}
public int getAge() {
return age
;
}
public void setAge(int age
) {
this.age
= age
;
}
public people() {
super();
}
public people(String name
, int age
) {
super();
this.name
= name
;
this.age
= age
;
}
}
class father extends people
{
private String familyname
= "Black";
public String
getFamilyname() {
return familyname
;
}
public void setFamilyname(String familyname
) {
this.familyname
= familyname
;
}
public father() {
super();
}
public father(String name
, int age
, String familyname
) {
super(name
, age
);
this.familyname
= familyname
;
}
public void show
() {
System
.out
.println("Hello.");
System
.out
.println("I am "+getName() + " " + getFamilyname());
}
public void showage() {
System
.out
.println("I am "+getAge()+" years old.");
}
}
class mother extends father
{
public mother() {
super();
}
public mother(String name
, int age
, String familyname
) {
super(name
, age
, familyname
);
}
public void show
() {
System
.out
.println("Ya ha lo!");
System
.out
.println("My name is "+getName());
System
.out
.println(getName()+" "+getFamilyname());
super
.showage();
}
}
abstract
class children extends mother
{
abstract
void mychildren();
static void like() {
System
.out
.println("I like ice cream!");
}
}
class son extends children
{
public void mychildren() {
System
.out
.println("Hi,I am" + getName()+ " " +getFamilyname());
}
}
class daughter extends children
{
public void mychildren
() {
System
.out
.println("Ya ha ... ...");
System
.out
.println("hell...o");
System
.out
.println("I am "+getName()+" "+getFamilyname());
}
}
interface animal
{
default void shotname() {
System
.out
.println("miao miao");
}
default void shothappy() {
System
.out
.println("miao!");
}
default void shotsad() {
System
.out
.println("...");
}
}
class cat {
private String itsname
;
public String
getItsname() {
return itsname
;
}
public void setItsname(String itsname
) {
this.itsname
= itsname
;
}
public cat() {
super();
}
public cat(String itsname
) {
super();
this.itsname
= itsname
;
}
}
class mimi extends cat
implements animal
{
public void show() {
this.shotname();
this.shothappy();
this.shotsad();
}
}
运行结果:
The Black!ver
.1.2
更新日志
新版本
1.2,增加更新日志
重写people,father,mother类,变量均私有化
修改抽象类children和类son,类daughter关系,调用更改为多态
增加animal接口和cat类,后续更新类mimi选择语句新功能
Hello
.
I am Jack Black
I am
30 years old
.
Ya ha lo
!
My name is Jenny
Jenny Black
I am
27 years old
.
Hi
,I amTom Black
I like ice cream
!
Ya ha
... ...
hell
...o
I am Penny Black
miao miao
miao
!
...