Java Object-Oriented understanding

Source: Internet
Author: User

Object-oriented: Object -oriented thinking emphasizes objects (objects with functions), and the process of focusing on action encapsulates the function into objects, we don't need to do anything we want to do, we just need to find the object with that function.

Three main features of object-oriented: encapsulation, inheritance, polymorphism

Encapsulation: is the preservation of a function, we put a method or function into the class, we need to find the object that encapsulates this function, and then call this object directly, the common functions or methods to encapsulate, can improve the reusability of code.

Benefits of Encapsulation:

1. Improved code reusability, we can encapsulate common methods into objects, when we need to use this function, only need to find the object with the function

2. Improve the security and standardization of the Code, specify the property of the object to private (privatized), and then to the property to configure the set () and Get Method () specification property acquisition and assignment

inheritance: with keyword: extends (subclass name extends parent class name)

An inherited class becomes a subclass or a derived class, and the inherited class becomes either a parent class or a base class or a superclass.

When you have the same properties or methods in multiple classes, we can extract these common properties and methods into a single class, and then inherit the individual class, saving the code and making the program easier to expand.

object is the parent class for all other Java classes

Inheritance: Subclasses can directly use properties and methods that are not private to the parent class after inheriting the parent class

Java can only be single-inheritance, one can have only one parent class, support multi-layer inheritance such as: b Inherit a C and then inherit B

When inheriting, understand the relationship between class and class, and make clear B is a

Polymorphism : a variety of forms that exist in a certain class of things

Characteristics of polymorphism:

Can hide object-specific features, only publicly shared members

The prerequisite for a polymorphic implementation is that two classes must have a relationship

Polymorphism improves code extensibility


A small rookie, a shallow understanding of Java, if there is a problem, but also hope to point out, thank you!

Java Object-Oriented understanding

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.