Understanding Java Object-oriented

Source: Internet
Author: User

Mastering classes and objects is the foundation of Java language programming. So, what exactly are classes and objects?

First, the object

In the real world, a thing that is everywhere is object, object is the entity that things exist, such as human, desk, computer, tall buildings and so on. The way human beings solve problems is always to simplify the complex things, and then think about what these objects are made of. Objects are usually divided into two parts, the dynamic and the static ones. Static part, as the name implies, is an active part, this part is called "attribute", any object will have its own attributes, such as a person, it includes height, weight, gender, age and other attributes. However, those who have these attributes will perform what actions are also a part of the discussion, the person can cry, smile, talk, walk, these are the behavior of this person (dynamic part), the human by exploring the properties of objects and observe the behavior of objects to understand the object.

          

Second, class

A class is a vector that encapsulates the properties and behavior of an object, whereas a class of entities that have the same properties and behavior are called classes. For example a bird, a bird encapsulates the common properties of all birds and shall have the behavior of its structure:

                    

Three, Package

Encapsulation is the core idea of object-oriented programming, which encapsulates the properties and behaviors of objects, while the carriers that encapsulate the properties and behaviors of objects are classes, which often hide their implementation details from the customer, which is the idea of encapsulation. For example, a user who uses a computer can do something with a finger-tapping the keyboard, and the user does not need to know how the computer works, even if the user may happen to know how the computer works, but does not rely entirely on the details of how the computer works when using the computer.

            

Iv. inheritance

Classes also have a relationship with classes, such as a department store class that is associated with a salesperson class, which is called an association between classes. Correlation is a general two-dollar relationship between two classes, such as a department store class and a salesperson class that is an association, and then the student class and the teacher class are also an association. There are many kinds of relationships between two classes, and inheritance is one of the associations.

                

V. Polymorphism

Polymorphism allows programs to be written in a uniform style to handle a wide variety of existing classes and related classes. The uniform style can be implemented by the parent class, and the object of the subclass can be instantiated according to the uniform style of the parent class. As the whole event is only dependent on the method of the parent class, it is possible to maintain and adjust the parent class's methods later, which reduces the difficulty of maintenance and saves time. When it comes to polymorphism, you have to mention abstract classes and interfaces, because polymorphic implementations do not rely on specific classes, but rather on abstract classes and interfaces.

Understanding Java Object-oriented

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.