For inheritance, there may be an argument that inheritance can only improve the functions of the original base class? If the answer is yes, the derived type is exactly the same type as the underlying class because it has exactly the same interface.
For its part, the concept of objects can bring us great convenience. It conceptually allows us to encapsulate all kinds of data and functionality together. This will properly express the concept of "problem space" without having to follow the basic
So far, we've seen how valuable Java can be in creating reusable pieces of code. The "Maximum reusable" unit of code has a class because it contains a tightly coupled unit attribute (field) and Unit action (method) that can be reused directly or
Libraries are often grouped according to their capabilities. Some libraries, such as those used, are interrupted and shelved. The standard Java library string and vector class is one such example. Other libraries are specially designed, such as
To eliminate cloning, you might think that you simply set the Clone () method to private (private), but it doesn't work because you can't take a basic class method and make it more "private" in a derived class. So it's not that simple. In addition,
When overriding a method, only the offending that has been defined in the underlying class version of the method is generated. This is an important limitation because it means that code that works with the underlying class is automatically applied
When learning inheritance, the most obvious way to create an inheritance hierarchy is to take a "pure" approach. That is, only methods that have been established in the underlying class or interface can be overwritten in the derived class, as shown
After learning the knowledge of polymorphism, because polymorphism is such a tool of "cleverness", it seems that everything should be inherited. But if the use of inheritance technology, it will make their own design unnecessarily complicated. In
When you create a new class by using the compositing method, you never have to worry about closing work on the member objects of that class. Each member is a separate object, so it gets normal garbage collection and closure-whether it's a member of
The order of the Builder calls is briefly described in chapter 4th, but that is what is said before inheritance and the problem of polymorphism are introduced. The Builder for the underlying class is definitely called in the builder of a derived
With inheritance technology, you can easily add new method declarations for an interface or combine several interfaces into a new interface. In both cases, you end up with a new interface, as shown in the following example:
: Horrorshow.java
Interfaces are only one form of "purer" than abstract classes. It uses more than that. Since interfaces have no specific implementation details-that is, not associated with storage and "interface"-there is no way to prevent multiple interfaces from
The "Interface" (interface) keyword makes the concept of abstraction deeper into one layer. We can think of it as a "pure" abstract class. It allows the creator to specify the basic form of a class: The method name, the argument list, and the return
Knowing that all the methods in Java are bound through late binding, you can write your own code to communicate with the underlying class. At this point, all the derived classes are guaranteed to work properly with the same code. Or alternatively,
In the 6th chapter, it is known that an object can be used as its own type, or as an object of its underlying type. The behavior used to get an object handle and use it as the underlying type handle is called "tracing"-because the drawing of the
Regardless of inheritance or compositing, we can create a new type based on an existing type. But in typical cases, we use compositing to implement the existing type of "regenerate" or "reuse" as part of the new type of foundation implementation
It is necessary to have an understanding of the entire initialization process, including inheritance, which has a holistic concept of what is happening in the process. Please observe the following code:
: Beetle.java
//The full process of
If the entire class is final (prefixed with the final keyword before its definition), it means that you do not want to inherit from this class, or that no one else is allowed to take this action. In other words, for this or that reason, our class
It is called this name, in addition to a certain historical reasons, but also because in the traditional sense, the method of the class inheritance graph is the root at the top, and then gradually downward expansion (of course, according to their
The most noteworthy part of inheritance is that it does not provide a method for the new class. Inheritance is an expression of the relationship between a new class and the underlying class. You can summarize the relationship by saying that the new
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.