当前位置:网站首页>2021-05-11 abstract class

2021-05-11 abstract class

2022-06-23 10:07:00 Deer like deer

abstract class

abstract Modifiers can be used to modify methods or classes , If the modification method , So methods are abstract methods , If you modify a class, it is an abstract class

There can be no abstract methods in an abstract class , But a class with abstract methods must be declared as an abstract class

Abstract classes cannot use new Keyword to create the object , It is used to let subclasses inherit

Abstract method , Only method declaration , There is no way to achieve , It's used for subclasses to implement

Subclass inherits abstract class , Then you must implement abstract methods that are not implemented by abstract classes , Otherwise, the subclass should also be declared as an abstract class

package oop.demo10;

//abstract abstract class 
public abstract class Action {
    
    // constraint - Someone helped us achieve 
    //abstract, Abstract method , Only the method name , There is no way to achieve 
    public abstract void doSomething();
    
    // You can't new This abstract class , It can only be implemented by subclasses : constraint 
    // Ordinary methods can be written in abstract classes 
    // Abstract methods must be in abstract classes 
    // Abstract abstract abstract 
    // The meaning of abstraction is to facilitate the use of code 
}

package oop.demo10;

// All methods of an abstract class , Inherits its subclass , Must implement its methods 
public class A extends Action {
    
    @Override
    public void doSomething() {
    

    }
}

原网站

版权声明
本文为[Deer like deer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230954195406.html