Home > Java > javaTutorial > body text

There are many things to pay attention to in Java inheritance

WBOY
Release: 2023-05-09 13:28:25
forward
1155 people have browsed it

Notes

1. Only multi-layer inheritance is allowed in Java, multiple inheritance is not allowed, and Java has single inheritance limitations.

2. In Java, all classes inherit the Object class directly or indirectly by default.

3. If a subclass inherits the parent class, it will have all the attributes and methods of the parent class! However, it should be noted that all (4) non-private (no private) operations belong to explicit inheritance (can directly utilize object operations), while all private operations belong to implicit inheritance (completed indirectly).

In the inheritance relationship, if you want to instantiate a subclass object, the parent class constructor will be called by default to initialize the attributes in the parent class, and then the subclass constructor will be called to initialize the attributes in the subclass. Property initialization, that is: by default, the subclass will find the parameterless constructor in the parent class.

Ctrl H displays the inheritance tree in the class.

Example

//多层继承
class A {}
class B extends A {}
class C extends B {}
 
//多重继承
class A {}
class B {}
class C extends A,B {}    // 一个子类继承了两个父类
Copy after login

The above is the detailed content of There are many things to pay attention to in Java inheritance. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!