Java Learning Essays (2) three major features of the Java language

Source: Internet
Author: User
Tags export class

1. Three main features of object-oriented

The three major features of object-oriented include: inheritance, encapsulation, polymorphism

(1) Inheritance: Refers to the subclass (export Class) to obtain the full functionality of the base class (all fields and methods). Note: In subclasses, the method that you want to call the base class can be called using Super. Method name.

Terminology: Inheritance is a hierarchical model of a junction class and allows and encourages the reuse of classes, which provides a way to articulate commonalities. A new class of objects can be derived from existing classes, a process known as class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class of the new class (The parent Class). Derived classes can inherit methods and instance variables from their base classes, and classes can modify or add new methods to make them more suitable for special needs.

(2) Encapsulation: It is the class that provides the function as a method to the user for invocation, but the specific implementation of the function is not visible externally.

Terminology: encapsulation is the process and data is surrounded, access to data only through the defined interface. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.

(3) Polymorphism: For polymorphism, personal feeling most important is the upward transformation. The so-called upward transformation means that when a function parameter is an object of the base class, the argument at the time of the call can be an object of the exported class.

Because the exported class is a superset of the base class, it may contain more methods than the base class, but it must have at least the methods contained in the base class. In the process of upward transformation, the only thing that can happen in the class interface is trimming, losing redundant methods, rather than acquiring them.

In this way, we can see how the upward transformation contributes to the simplification of the program:

Cases:

As you can see, write a tune () method for each class without using an upward transformation.     However, by using an upward transformation, you only need to implement the tune method in the base class, and at the time of invocation, the method of invoking different classes can be implemented by different arguments.  For Brass Frenchhorn = new Wind ();      In fact, a brass object is defined, and it is understood that the object's reference in the stack determines the behavior of the object, not the object entity in the stack, through the understanding of the Java creation object. Terminology: polymorphism refers to allowing objects of different classes to respond to the same message. Polymorphism consists of parameterized polymorphism and inclusion polymorphism. Polymorphism language has the advantage of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.

Java Learning Essays (2) three major features of the Java language

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.