The idea of Java object-oriented programming

Source: Internet
Author: User


Object-oriented three features: encapsulation, inheritance, polymorphism
Packaging:
Syntax: Property privatization (private), providing a way to provide relative get/set to access (public),

The judgment of the business logic corresponding to the data of the attribute in the method of Set/get
Idea: Packages outside of the program cannot directly access the properties of this class, and need to pass through the methods provided by this class

Access to the properties of this class, thereby increasing the code'sSecurity.
Other points of knowledge related to:
Construction method: Used to describe the object creation process, you canConstructs a method to quickly create an object.
This keyword: represents this class of objects, calls the properties of this class,Methods, construction methods.
Method Overloading: Method name is the same, parameter list is not the same
Inherited:
Syntax: Subclass extends Parent class
Thought: A common feature or behavior described by multiple classes can
The common parts of the class are extracted to create their parent class.
Benefits of Inheritance: Subclasses share the code of the parent class, which improves the reusability of the Code;
                 later extension and maintenance, just add the corresponding subclass.
    related to other knowledge points:
     Super Keyword: An object representing the parent class, calling the properties of the parent class, method, construction method.
     abstract Keywords: abstract, decorated class, cosmetic method.
     static keyword: static, Decorated property, method, code block, inner class
     final keyword: final, cosmetic property , method, class
     method Override: Method name is the same, parameter list is the same, return value type Same,

modifier greater than or equal to the access modifier of the parent class
Polymorphic:
Syntax: Parent class object name =new subclass ();
Thought: A reference to a parent type can point to the memory space of a child class object in memory,
It is convenient to design the parameters and return value types of the method, you can
Designed to be a parent object, such a method is relatively concise when implemented, and in late
The method is easier to extend.
In code, polymorphic use is more of a parent class reference to a subclass object,
Automatically type conversions (up), but sometimes you need to call subclasses
In their own things, this time you need to also atomic class, called coercion type conversion
(downward transition), use the instanceof operator to do the type of
Judge.

The idea of Java object-oriented programming

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.