【九】抽象类和抽象函数

 1 class Chinese extends AbsPerson{
 2 
 3     Chinese(){
 4         super();
 5         System.out.println("Chinese的构造函数");
 6     }
 7     //上面是该抽象类的构造函数
 8     void eat(){
 9         System.out.println("用筷子吃饭");
10     }
11     //override复写的抽象类里面的抽象函数,这样Chinese就可以用了
12 }
 1 abstract class AbsPerson{
 2     AbsPerson(){
 3         System.out.println("AbsPerson的构造函数");
 4     }
 5     //抽象类的构造函数,抽象类也是有构造函数的,在生成对象的时候会被调用
 6     String name;
 7     int age;
 8     
 9     void introduce(){
10         System.out.println("my name is " + name +",my age is " + age);
11     }
12     
13     abstract void eat();
14 }
1 class TestAbs{
2     public static void main(String args []){
3         AbsPerson ap = new Chinese();
4         ap.eat();
5     }
6 }

这个test里面也用到了向上转型,还有调用的是指向的子类的方法这个点

 

 

 

要断电了,先写到这里

posted on 2015-01-12 23:04  相东  阅读(152)  评论(9编辑  收藏  举报

导航