interface tree{}class appleTree implements tree{}class test{
public static void main(String args[]){
tree t=new appleTree();
}
}
//这个问题是一个经典的引用的类型问题,我这里没有用抽象类,而是用的interface,这样
//做是面向对象编程语言的重要特性,现在不能理解,以后会慢慢明白的:)
public static void main(String args[]){
tree t=new appleTree();
}
}
//这个问题是一个经典的引用的类型问题,我这里没有用抽象类,而是用的interface,这样
//做是面向对象编程语言的重要特性,现在不能理解,以后会慢慢明白的:)
if(男人){
男人.穿();
}
else if(女人){
女人.穿();
}
首先代码不是好看,最差的是万一现在有了一个人妖,既不是男人,也不是女人,怎么办,该代码,只有这么办。但是假如用继承的话,那么一切都好办了:
abstract class Person{
abstract 穿();
}
Man extends Person{
穿(){ }
}
Woman extends Person{
穿(){ }
}
class Main{
void 大家来穿衣服{
Person person=loadPerson();
person.穿();
}
}
一切OK..!