java抽象类(课堂)
2016-01-14 00:02
375 查看
package com.qianfeng.day10.demo3;
// abstract ['æbstrækt] 修饰的方法只有方法签名,没有具体的实现,子类必须得重写
// abstract修饰的类,叫抽象类,可以有抽象方法,也可以没有,反过来不成立
// 存在在抽象方法的类必须是抽象类
/*
*抽象类的知识点:
*属性:
* 1、没有抽象属性,有其他普通属性
*
*类
* 1、使用abstract进行修饰
* 2、无法通过 new
构造对象,只能使用继承,但是,存在构造方法。
* 3、可以有抽象方法,也可以没有,反过来不成立,存在在抽象方法的类必须是抽象类
* 4、如果抽象类中有多个抽象方法,而子类继承后,不重写父类所有的抽象方法,那么
*
要么子类是报错的,要么让子类声明为抽象类
* 5、 final abstract
2 者对立,相矛盾,只能存其一
*
*方法
* 1、抽象方法使用abstract进行修饰,只有方法签名,没有方法体,只存在抽象类中
* 2、static abstract
不能同时存在,static修饰的方法不能重写,abstract必须要重写
* 2
者对立,相矛盾,只能存其一
* 3、abstract
final 不能同时存在, final修饰的方法为最终方法,不能被重写,
* 而abstract必须要重写,
2者对立,相矛盾,只能存其一
* 4、private
abstract 不能同时存在, private修饰的方法为私有方法,不能被继承,
* 而abstract必须要重写,
2者对立,相矛盾,只能存其一
*/
public abstract class Father {
//Illegalmodifier for the field name;
//onlypublic, protected, private, static, final, transient
//&volatile are permitted
//abstractString name;
publicFather(){
}
publicvoid eat(){
System.out.println("Father.eat()");
}
publicabstract void work();
publicabstract void method();
//Theabstract method method2 in type Father can only set a visibility modifier,
//oneof public or protected
//publicabstract static void method2();
}
package com.qianfeng.day10.demo3;
//The type Son must implement the inheritedabstract method Father.work()
public class Son extends Father {
publicstatic void main(String[] args) {
Son son = new Son();
son.eat();
//Cannot instantiate the type Father
//Father father = new Father();
Father father = new Son();
}
@Override
publicvoid work() {//必须重写父类方法
}
@Override
publicvoid method() {
}
}
package com.qianfeng.day10.demo3;
// abstract ['æbstrækt] 修饰的方法只有方法签名,没有具体的实现,子类必须得重写
// abstract修饰的类,叫抽象类,可以有抽象方法,也可以没有,反过来不成立
// 存在在抽象方法的类必须是抽象类
/*
*抽象类的知识点:
*属性:
* 1、没有抽象属性,有其他普通属性
*
*类
* 1、使用abstract进行修饰
* 2、无法通过 new
构造对象,只能使用继承,但是,存在构造方法。
* 3、可以有抽象方法,也可以没有,反过来不成立,存在在抽象方法的类必须是抽象类
* 4、如果抽象类中有多个抽象方法,而子类继承后,不重写父类所有的抽象方法,那么
*
要么子类是报错的,要么让子类声明为抽象类
* 5、 final abstract
2 者对立,相矛盾,只能存其一
*
*方法
* 1、抽象方法使用abstract进行修饰,只有方法签名,没有方法体,只存在抽象类中
* 2、static abstract
不能同时存在,static修饰的方法不能重写,abstract必须要重写
* 2
者对立,相矛盾,只能存其一
* 3、abstract
final 不能同时存在, final修饰的方法为最终方法,不能被重写,
* 而abstract必须要重写,
2者对立,相矛盾,只能存其一
* 4、private
abstract 不能同时存在, private修饰的方法为私有方法,不能被继承,
* 而abstract必须要重写,
2者对立,相矛盾,只能存其一
*/
public abstract class Father {
//Illegalmodifier for the field name;
//onlypublic, protected, private, static, final, transient
//&volatile are permitted
//abstractString name;
publicFather(){
}
publicvoid eat(){
System.out.println("Father.eat()");
}
publicabstract void work();
publicabstract void method();
//Theabstract method method2 in type Father can only set a visibility modifier,
//oneof public or protected
//publicabstract static void method2();
}
package com.qianfeng.day10.demo3;
//The type Son must implement the inheritedabstract method Father.work()
public class Son extends Father {
publicstatic void main(String[] args) {
Son son = new Son();
son.eat();
//Cannot instantiate the type Father
//Father father = new Father();
Father father = new Son();
}
@Override
publicvoid work() {//必须重写父类方法
}
@Override
publicvoid method() {
}
}
相关文章推荐
- java类加载机制与反射
- java内部类(成员)(课堂)
- 转: 利用Spring AOP自定义注解解决日志和签名校验
- 深入理解Java:注解(Annotation)自定义注解入门
- Spring3 MVC Login Interceptor(Spring 拦截器)
- myeclipse10 class 反编译
- myeclipse 快捷键
- 【spring-boot】spring aop 面向切面编程初接触
- springmvc 乱码问题
- maven搭建 struts2+spring+hibernate
- maven搭建 springmvc+mybatis应用
- Java中过滤出字母、数字和中文的正则表达式
- spring-Ioc浅析
- java complier compliance level and jdk version
- java 连接presto实现SQL查询
- java包用法(课堂)
- java--super_get_set_继承与拓展_调用由近到远(课堂)
- JDK配置
- java基础-java反射机制
- java--String,toString(课堂)