本文共 435 字,大约阅读时间需要 1 分钟。
2009-7-25
抽象类:
(1)语法:abstract 类名:public abstract class 类名
(2)特点:<1>抽象类不能实例化
<2>抽象类体里面应该包含抽象方法(方法声明)--<1>在返回值类型前被 abstract 修饰 <2>无方法体
<3>继承了抽象父类的子类需对抽象父类中的抽象方法提供实现---重写
<4>如果子类继承了抽象父类,且没有对父类中的抽象方法进行重写,那么该子类将变为抽象类
<5>抽象类中不一定有抽象方法,但是包含了抽象方法的类就一定是抽象类
例: public abstract void say(); (3)作用:<1>用于继承基础之上 <2>给子类提供模板 (4)抽象类的形成条件: <1>类中至少由一个抽象方法 <2>子类继承了父类的抽象方法,但是对于父类的抽象方法有一个没有实现,则子类也是抽象类 <3>类实现了某个接口,但没有全部实现接口中的方法,则也为抽象类 (5)多态 (6)设计模式<2>:模板设计模式转载地址:http://xyxbi.baihongyu.com/