JAVA three major features

Source: Internet
Author: User

Java has three major features, encapsulation, inheritance, polymorphism, but the average person is not able to understand these three characteristics I'm going to share my experience here.

1. Encapsulation: The public public, the private private

The properties of the class are private, the properties of the class are generally private, and the method of the class: the public public, the private private;

class, encapsulates data and methods, encapsulates the implementation process, interfaces are parameters and return values; Data prototype class: Also called entity class

1) Get/set method; a get is only provided for a property that does not provide a set method, which is read-only and cannot be modified outside the class;

2) provide unified parameter checking, give and check on set, judge legality and security; The properties are private and provide Set/get method, which is a general component called JavaBean;

2, Inheritance: Any parent class where applicable, subclasses must be applicable

Simple code reuse does not need to inherit extends: inheritance, is actually the extension of the parent class;

What is the process of generating an object?

1) Allocating object space;

2) Assign the initial value to the attribute; boolean:false; value type: 0 or 0.0; Object type: null;

3) Call the constructor method;

3. Polymorphic: Overloads of multiple methods in a class are called polymorphic, and the overrides of methods in parent-child classes are also called polymorphic.

There are two types of polymorphism: one is the reload of the method, the other is the method's cover

Polymorphic polymorphic and Object polymorphism (multiple forms of an object). Polymorphic must look at the subclass object as a parent object,

All polymorphism can be attributed to two theorems:

1). You can look at the object as a parent class object, once this is done, you can only call the parent class in the original defined properties and methods, that is, the extension of the subclass of the method or property can not be called.

2). When we look at a class object as a parent object, if the subclass overrides a method in the parent class, the child class is actually called after the overridden method.

JAVA three major features

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.