java中的抽象类(abstract)

具体看代码

 1 abstract class student {// 抽象方法放在类中,不能有new创建对象,没意义,必须让子类复写方法,复写后仍未抽象类
 2     abstract void study();// 由void study(){}改的
 3     // 抽象方法一定有抽象类,必须有关键字修饰
 4     // abstract void
 5     // study1();//如果有这个,子类必须复写其方法,如果不复写,在子类前必须加abstract,且必须将此方法放在子类中,前要加abstract
 6 }
 7 
 8 class BaseStudent extends student {
 9     void study() {
10         System.out.println("base studing");
11     }
12 
13 }
14 
15 class AdvStudent extends student {
16     void study() {
17         System.out.println("adv studing");
18     }
19 }
20 
21 public class TestAbstract {
22 
23     public static void main(String[] args) {
24         new BaseStudent().study();
25     }
26 
27 }
View Code

 

posted @ 2013-12-21 14:11  天天AC  阅读(162)  评论(0编辑  收藏  举报