Java Basics (ii)-classes, Objects

Source: Internet
Author: User

Class One: The purpose of creating a new data type by encapsulating other data types. You can include basic data types and non-basic data types inside a class

1. The source code of the Java language is stored in the file as a unit of the class.

2. There are two formal names in the body of a class: attributes and member variables .

3. Create a reference to a class (declaring a variable of a class): class name + space + class variable name

4. Create an object of a class (an entity that creates a class): new + space + class name + (). In the Create entity procedure, let the variable of the class declared in 3 point to the Entity.

5. Because the reference created refers to the entity of the class, the variable represents the object of the class. When you use a property in a class, you can directly use the reference (variable) you create to point to the object of the class.

The format is: the variable name of the class + "." + property name

second, object: New creates the object of the class

1, when using the object, is through the Object's reference, to manipulate the Object's Entity.

2. An object can be pointed to by multiple references

3. If an object does not point to any of the references, the object will no longer exist.

Iii. relationships between classes, objects, and references

1, the data type of the entire composition of the new data Type--class

2. Entities that create data based on the definition of a class-object

3. Variables created through the Class--reference

4, reference to the object, is created through the class, is the bearer of classes and objects in the middle of a bridge.

Iv. syntax for using object attention

1, the reference can not point to any object.

2, If the reference does not point to any object, by reference to manipulate the object will cause a null pointer exception Problem. NullPointerException

  

  

  

  

Java Basics (ii)-classes, Objects

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.