Detailed explanation of abstract classes and methods in Java programming

Common knowledge points of abstract classes and methods:

(1) Abstract classes are inherited classes, and subclasses must implement all abstract methods in abstract classes, unless subclasses are also abstract classes.

That is, if the subclass is also an abstract class, you can not implement the abstract methods in the parent class. However, if there is a non abstract class

It inherits from the abstract subclass and needs to implement the abstract subclass. All abstract methods of the abstract parent class of the abstract subclass are calculated together with the new accounts and the old accounts.

(2) Abstract classes cannot be decorated with final.

(3) Abstract classes cannot be instantiated, that is, you cannot create them with the new keyword.

(4) Abstract classes can contain abstract methods and non abstract methods. Abstract methods have no method body, that is, no concrete implementation,

It only defines what functions it has, but non abstract methods contain method bodies.

eg:

Abstract parent class person:

Non Abstract subclass teacher:

Non Abstract subclass student:

Abstract subclass othersperson:

The non Abstract subclass extendsouthersperson inherits from the abstract subclass othersperson:

Test code:

Console output:

Teachers eat, teachers sleep, life lies in exercise =============== students eat, students sleep, life lies in exercise

summary

The above is all about the detailed explanation of Java programming abstract classes and methods in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this website:

Static class in Java

Java compressed file tool class ziputil usage method code example

Understanding of subclass overriding parent method in Java programming

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>