if (p1 instanceof Man) {
Man m1 = (Man) p1;
m1.entertainment();
}
if (p1 instanceof Person) {
System.out.println("你好!");
}
}
public void show(Person p) {//Person p = new Man();
}
class Person {
private String name;
private int age;
int id = 1001;
public Person() {
super();
}
public Person(String name, int age) {
super();
this.name = name;
this.age = 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 void walk(){
System.out.println("人走路");
}
public void eat(){
System.out.println("人吃饭");
}
}
class Man extends Person{
boolean smoking;
int id = 1002;
public Man() {
super();
}
public Man(boolean smoking) {
super();
this.smoking = smoking;
}
public boolean isSmoking() {
return smoking;
}
public void setSmoking(boolean smoking) {
this.smoking = smoking;
}
public void walk(){
System.out.println("男人笔挺的走路");
}
public void eat(){
System.out.println("男人应该多吃肉!");
}
public void entertainment(){
System.out.println("男人请客");
}
}
class Woman extends Person{
private boolean isBeauty;
public boolean isBeauty() {
return isBeauty;
}
public void setBeauty(boolean isBeauty) {
this.isBeauty = isBeauty;
}
public Woman() {
super();
}
public Woman(boolean isBeauty) {
super();
this.isBeauty = isBeauty;
}
public void walk(){
System.out.println("女人窈窕的走路。。。");
}
public void eat(){
System.out.println("女人应该少吃,减肥");
}
public void shopping(){
System.out.println("女人爱购物");
}
}