Classes and Objects acquaintance

 

What is class?

1, the class itself does not take up memory space, only when you create an object, the object occupies memory space when the class

2, can be considered to create an object class template, a blueprint. All objects are constructed by its own class

3, the structure of the class is a class of certain entities or a static characteristic and dynamic characteristic things composition

4, the smallest class is the java program execution unit, object-oriented (Python function of object-oriented programming +)

5, can not represent a source file of a class, as a source file can have a plurality of classes, the class is only one public class

6, the class name capitalized, use the class keyword modifications

 

What is an object?

1, the object is achieved by the class to be instantiated, and occupies memory

2, abstract class can be seen as an object, the object is regarded as an instance of the class

3, concerned with programs running characteristics

4, construct an object: object name = new class name class name ();

5, class object instantiated only by new new, but also by clone (cloning), reflected: newInstance (), Agent: Proxy.newInstance ();

 

Class member variables and methods Variables What is the difference?

1, is a member variable with default values, variables without initial value method

  The default value of numeric types of default: 0 Boolean: Default type of fault String Default: null array type: null

2, member variables can be static public private default (default) protected modifier such as modified

3, the initial value of a member variable can be assigned, but can not perform logical operations to the methods;

 

Access modifier introduced:

1, Java access modifiers include: public private protected default (default)

2, private can only be accessed in this category, protect and default (default) class can be accessed the same package, but can not cross-package, public across package

 

What is the method?

Definition 1, the method

  Permissions modifier return type method name (parameter type parameter name) {

  The method body

  return return value

  }

2, representative of the result type void function is executed after the completion of the return value is null

3, the method returns a value need to use return a return value, the method terminates after the return, the code not be followed

4, need to return a consistent value type, and method return value type need not match it is automatically converted or cast

5, the method of performing the necessary conditions: the data type of the parameter, the sequence number must be consistent with the method defined

6, null pointer can not call any methods

7, the benefits of the method * to improve reusability of code to enhance the development efficiency * * * readable structured programming, optimizing the structure, reduce redundant code

8, this: the current class object, and who it is who to call

 

An array of objects Introduction:

1, the class name [] array name = new class name [array size]; default of each element is empty

2, the array element of the array type is an object of the class created;

3, call the object's member variables or methods: array name [n] member variables (member method.

 

Guess you like

Origin www.cnblogs.com/daguoshi/p/10939675.html