Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the points for attention in java inheritance

Shulou Source: shulou.com Published: 2022-05-31 10:48:19 11月13日 Update

This article mainly explains "what are the points for attention in java inheritance?" friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the points for attention in java inheritance?"

Pay attention

1. Only multi-tier inheritance is allowed in Java, but not multiple inheritance. Java has the limitation of single inheritance.

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

3. If the subclass inherits the parent class, it will have all the properties and methods of the parent class! It is important to note, however, that all (4) non-private (no private) operations are explicitly inherited (you can take advantage of object operations directly), while all private operations are implicitly inherited (indirectly).

In the inheritance relationship, if you want to instantiate the subclass object, the parent class construction is called by default to initialize the attributes in the parent class, and then the subclass construction is called to initialize the attributes in the subclass, that is, by default, the subclass will find the no-parameter constructor in the parent class.

Ctrl+H displays the inheritance tree in the class.

Example

/ / Multi-tier inheritance class A {} class B extends A {} class C extends B {} / multiple inheritance class A {} class B {} class C extends A Magi B {} / A subclass inherits two parent classes so far, I believe everyone has a deeper understanding of "what are the points for attention in java inheritance", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Subclass middle property method content multi-layer instance object learning private practical deeper two interest practicality actual situation simple operation more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology OPPO Reno Apple Docker