java抽象类(课堂)



package com.qianfeng.day10.demo3;

 

// abstract ['æbstrækt] 修饰的方法只有方法签名,没有具体的实现,子类必须得重写

// abstract修饰的类,叫抽象类,可以有抽象方法,也可以没有,反过来不成立

//   存在在抽象方法的类必须是抽象类

/*

 *抽象类的知识点:

 *属性:

 * 1、没有抽象属性,有其他普通属性

 *

 *

 * 1、使用abstract进行修饰

 * 2、无法通过 new 构造对象,只能使用继承,但是,存在构造方法。

 * 3、可以有抽象方法,也可以没有,反过来不成立,存在在抽象方法的类必须是抽象类

 * 4、如果抽象类中有多个抽象方法,而子类继承后,不重写父类所有的抽象方法,那么

 *         要么子类是报错的,要么让子类声明为抽象类

 * 5 final abstract   2 者对立,相矛盾,只能存其一

 *

 *方法

 * 1、抽象方法使用abstract进行修饰,只有方法签名,没有方法体,只存在抽象类中

 * 2static abstract   不能同时存在,static修饰的方法不能重写,abstract必须要重写

 *    2 者对立,相矛盾,只能存其一

 * 3abstract final  不能同时存在, final修饰的方法为最终方法,不能被重写

 *   abstract必须要重写, 2者对立,相矛盾,只能存其一

 * 4private 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() {

            

      }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小猿成长

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值