Java Object-oriented summary

Source: Internet
Author: User
Tags null null

1 objects

1.1 What is an object?

    First of all, the object is not Java, in fact, he is only a concept, a problem-solving program design method of thinking. To understand objects, you have to combine them with object-oriented. A class is formed after an object-oriented abstraction of attributes and behaviors that are common to a class of things. And a real example of a class is called an object. So it can be seen that there is a relationship between a class and an object: A class is an abstraction of a set of objects with a common property name and behavior, and an object is a real example of a class.

A class is a reflection of an entity in the real world or the mind world in a computer that encapsulates data and the operations on that data. The class describes a collection of objects with the same attributes (data elements, state variables) and behaviors (Operations on data elements, state variables), and if I need a tool with some functionality, I can customize the class with the data I need and the functionality that this class provides.An object is a variable that has a class type. Classes and objects are the most basic concepts in object-oriented programming techniques. A class is an abstraction of an object, and an object is a concrete instance of a class. Classes are abstract, do not occupy memory, and objects are specific and occupy storage space. A class is a blueprint for creating objects, which is a software template that defines methods and variables that are included in a particular type of object.

Java is an object-oriented programming language, objects are abstracted from the class, all the problems are handled by objects, objects can manipulate the properties and methods of the class to solve the problem, so it is necessary to understand the production, operation and extinction of objects. An object can be thought of as an abstraction of a special case in a class of things, which deals with the problems of such things, and creates objects in the Java language through the new operator.

1.2 Creation and extinction of objects-----See < In-depth understanding of Java Virtual machines >

1.3 Object and Object references
The following expression:    a a1 = new A (); It represents a is a class, A1 is a reference, A1 is not an object, new A () is the object, and the A1 reference points to the object of new A ().

In Java, "=" cannot be considered an assignment statement, it does not assign an object to another object, its execution essentially passes the address of the right object to the left reference, so that the left reference points to the object on the right. There is no pointer on the Java surface, but its reference is essentially a pointer, and the reference is not the object, but the address of the object, so that the reference points to the object. In Java, the "=" statement should not be translated into an assignment statement because it does not perform a process of assignment, but rather a process of passing an address, and being translated into an assignment statement can cause many misunderstandings and inaccurate translations.

Again such as: A A2; It represents a is a class, A2 is a reference, A2 is not an object, and the object pointed to by A2 is null null;

Again such as: a2 = A1; It stands for, A2 is a reference, A1 is also a reference, and the address of the object pointed to by A1 is passed to A2, which makes A2 and A1 point to the same object.

In summary, it can be simply remembered that, at initialization, the "=" statement to the left of the reference, the right new out of the object.
         when the "=" statement is referenced around the back, the reference to the left and right refers to the object to which the reference is pointing. again the so-called instance, is actually the synonym of the object.

2 Java three major features

2.1 Java Inheritance

Inheritance is the most significant feature of object-oriented. Inheritance is the derivation of new classes from existing classes, which can absorb data properties and behaviors of existing classes, and can extend new capabilities. Java inheritance is the technique of building a new class using the definition of an existing class, and the definition of a new class can either add new data or new functionality, or use the functionality of the parent class, but not selectively inherit the parent class. This technique makes it easy to reuse the previous code, greatly shortening the development cycle and reducing development costs.

Inheritance is a cornerstone of Java object-oriented programming technology because it allows classes of hierarchical hierarchies to be created. Inheritance can be understood as the process by which an object obtains a property from another object. If Class A is the parent class of Class B, and Class B is the parent class of Class C, we also call C a subclass, and Class C inherits from Class A. In Java, the inheritance of a class is a single inheritance, meaning that a subclass can have only one parent class. The most commonly used two keywords in inheritance are extends (is-a, what is a thing) and implements (Has-a, which has a function). The use of these two keywords determines whether an object and another object are Is-a (is a) relationship. By using these two keywords, we can implement one object to get the properties of another object. All Java classes are inherited by the Java.lang.Object class, so object is the ancestor class for all classes, and all classes must have a parent class except for object. The extends keyword can be used to declare that a class inherits from another class, and by using the keyword extends, subclasses can inherit all the methods and properties of the parent class, but cannot use private (private) methods and properties. we can determine the subclass Is-a parent class by using the instanceof operator.

2.2 Java polymorphic

2.3 Java Package

2.4 Java extends and implements usage similarities and differences analysis

Java Object-oriented summary

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.