The seventh chapter object-oriented (i.)

Source: Internet
Author: User

7 Object-oriented


7.1 Classes and objects

    • Class: A reflection of a real-world entity in a computer that encapsulates data and the operations on that data.

    • Object: A concrete instance of a class


7.2 member variables and local variables

7.2.1 Range of Action

member Variables act on the entire class.

A local variable acts on a method or statement.

7.2.2 in-memory locations

member variables in heap memory

local variables in stack memory


7.3 Anonymous Objects

cannot create object name: New Car ();

an anonymous object is a simplified form of an object

7.3.1 Use Cases

1. Only one call is made to the method of the object

2. Passing as the actual parameter


7.4 Constructors

7.4.1 Features

      • The function name is the same as the class name

      • No return value type

      • You cannot write a return statement

7.4.2 Effect

Initializing objects

7.4.3 Call

when an object is established, it is automatically called and executed only once.

calls between multiple constructors, using the This keyword: this ([parameter, ...] ); [] means dispensable. This can only be defined in the first row of the constructor, and the initialization action is performed first


7.5 this keyword

Represents the reference to the object to which the function belongs

7.5.1 Effect

      • Used to distinguish variables of the same name

      • Used to call each other between constructors


7.6 Default Constructors

    • When there is no constructor in the class, the system defaults to the constructor for the class to add an empty argument to facilitate initialization of the class.

    • When a constructor is defined in a class, the default constructor has no


7.7 Building Code Blocks

7.7.1 says

{}, the code is written inside {}.

7.7.2 effect

Initializing objects

7.7.3 Call

An object is executed as soon as it is established, and takes precedence over a constructor function.

7.7.4 the difference between constructing code blocks and constructors

        • Building blocks of code is a unified initialization of all objects;

        • The constructor is the initialization of the corresponding object.

This article is from the "Java Basics" blog, so be sure to keep this source http://8163413.blog.51cto.com/8153413/1690320

The seventh chapter object-oriented (i.)

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.