JAVA class and object (1) ---- basic concepts, java ----

Source: Internet
Author: User

JAVA class and object (1) ---- basic concepts, java ----

Basic object-oriented concepts

Object-oriented is an emerging programming method, or a new programming specification, the basic idea is to use objects, classes, inheritance, encapsulation, messages and other basic concepts for program design. It constructs a software system from an objective object in the real world, and tries its best to use the natural way of thinking in the system structure.

Object: an object is an entity used to describe objective things in a system. It is a basic unit of a system. An object consists of attributes and a group of services that operate on attributes.

Class: many things are summarized and divided into several ways of thinking that humans often use to understand the objective world. The classification principle is abstract. A class is a set of objects with the same attributes and services. It provides a unified abstract description for all objects belonging to the class. The class includes attributes and services. In object-oriented programming language, a class is an independent program unit. It should have a class name and contain two main parts: attribute description and service description. The relationship between a class and an object is like the relationship between a mold and a casting. The result of class instantiation is an object, and the abstraction of A Class Object is a class.

Message: a message is a service request sent to an object. It includes the Object ID, service ID, input information, and answer information of the provided service. A service is usually called a method or function.

 

Basic object-oriented features:

1. encapsulation: Combine object attributes and services into an independent unit, and hide the internal details of the object as much as possible.

2. Inheritance: Objects of special classes have all the attributes and services of their general classes. They are called special classes that inherit general classes. For example, a passenger can inherit from ships and adults can inherit from humans. In addition, a class can inherit attributes and services from multiple general classes, which are called multi-inheritance. In java, a general class is called a parent class (SuperClass, SuperClass), and a special class is a SubClass (SubClass ).

3. Polymorphism: attributes defined in a general class or services that are inherited by special classes can have different data types or show different behaviors, this makes the same attribute or service have different semantics in the general class and its special classes. For example, the "plotting" method of "ry", "elliptic" and "polygon" are both subclasses of" ry", and the "plotting" method has different functions.

Related Article

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.