This article describes the concepts and usage of Java abstract classes. Share it for your reference, as follows:
Abstract: It is a general description of a thing
Abstract method: A method modified with abstract. This method only declares the return data type, method name and required parameters, and does not have a function body. Such as abstract void study();
Abstract class features:
1. Abstract classes do not necessarily contain abstract methods; but abstract methods must be in abstract classes.
2. Abstract classes do not have actual functions and can only be used to derive subclasses.
3. The abstract class can contain constructors, but the constructor cannot be declared as abstract. Member methods in abstract classes include general methods and abstract methods
4. Both abstract methods and abstract classes must be modified by the abstract keyword
5. Abstract classes cannot create objects with new. All abstract methods must be copied by the subclass and the subclass object call is created.
6. To be used, the subclass must rewrite all abstract methods and create a subclass call after the subclass is created. If the subclass only rewrites part of the abstract method, then the subclass is still an abstract class.
7. The abstract method must be public or protected (because if it is private, it cannot be inherited by the subclass, and the subclass cannot implement the method)
abstract class Student//Abstract class { private String name; private int age; abstract void study();//Abstract method Student(String name,int age) { this.name=name; this.age=age; }}class GaoZhongStudent extends Student{ private String xuehao; GaoZhongStudent(String name,int age,String xuehao) { super(name,age);//Execute the parent class constructor this.xuehao=xuehao; } public void study() { System.out.println("study gaozhong"); }}class ChuZhongStudent extends Student{ ChuZhongStudent(String name,int age) { super(name,age); } public void study() { System.out.println("study chuzhong"); }}class abstractDemo{ public static void main(String[] args) { ChuZhongStudent p1=new ChuZhongStudent("zhangsan",20); p1.study(); GaoZhongStudent p2=new GaoZhongStudent("lisi",20,"yaohua001"); p2.study(); }}For more Java-related content, readers who are interested in this site can view the topics: "Introduction and Advanced Tutorial on Java Object-Oriented Programming", "Tutorial on Java Data Structure and Algorithm", "Summary of Java Operation DOM Node Skills", "Summary of Java File and Directory Operation Skills" and "Summary of Java Cache Operation Skills"
I hope this article will be helpful to everyone's Java programming.