008 class concept, creation and use of

Class generally consists of two parts:

Properties --- --- member variable "is.

Behavior --- --- member method "can do.

Class is a fictional template, such as design drawings

Object is the materialization of the class, for example, according to design drawings produced by actual thing.

Typically, a class can not be used directly, we need to create an object based on the class to use.

1, lead pack, which is the class that you want to use, in what position.

import package name. class name --- "Package Name package needs to include one or more layers path

For example: import cn.lwkj.day03.demo01.Student;

And for a current class belong to the same package, the package may be omitted guide statements are not written.

2, create, format:

= New class name of the object class name ();

Example: Student stu = new Student ();

3, use, divided into two cases,

Use member variables: Object-member variable name.

Use member method: Object members of the method name (parameters)

Precautions:

1, if no member variable assignment, it will assign default values, and array assignment similar to the default values.

2, members of the method is actually saved an address value pointing to the address stored in the memory (zone method) method.

The object name (stored in the memory stack) is stored in the address, point to the address stored in the memory (heap) class object.

3, when the object to invoke the method, the specific method will stack area method, will perform over the stack.

4, class method definition if there is no argument, do not write void.

public String getName()

{

       return name;

}

Published 70 original articles · won praise 4 · Views 3977

Guess you like

Origin blog.csdn.net/l0510402015/article/details/104085077