In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "what is the nature of Java object-oriented inheritance". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the nature of Java object-oriented inheritance?"
1. What is inheritance?
(1) to improve the reusability of the code
(2) encapsulate the same functional module into the method and call the method when it is needed to achieve the purpose of code reuse.
(3) extract the same class tolerance from multiple classes through inheritance and become a new class, so that other classes have a relationship with the current new class, so as to achieve the purpose of code reusability Note: Java is a single inheritance different from C++, C++ can inherit more.
two。 Inherited format
Keyword extends
3. Inherited properties
* the subclass has attributes and methods of the parent class that are not private.
* subclasses can have their own properties and methods, that is, subclasses can extend the parent class.
* subclasses can implement the methods of the parent class in their own way.
* the inheritance of Java is single inheritance, but it can inherit multiple inheritance. Single inheritance means that a subclass can only inherit one parent class. Multiple inheritance means, for example, class B inherits class A, and class C inherits class B, so according to the relationship, class B is the parent of class C, and class An is the parent of class B. this is a feature that distinguishes Java inheritance from C++ inheritance.
* improve the coupling between classes (the disadvantage of inheritance, the higher the degree of coupling, the closer the relationship between the code, the worse the code independence)
4. When the subclass inherits the parent class, what happens in memory when we create the subclass object?
As shown below:
Photo source Han Shunping bilibili link
It can be seen that the subclass object has all the properties of the parent class, but whose will we visit if we access name?
5. Permission modifier
Note: both properties and methods apply. Default is the return type (data type). Nothing needs to be written before it.
At this point, I believe you have a deeper understanding of "what is the nature of Java object-oriented 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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.