java core technology read 10 (b) - object-oriented programming

Objects

Programming and object-based programming process based on the difference that the algorithm for solving the design process to re-run the design data structure is formed, and is based on the object data structure to find the reverse process redesign algorithm. This will help us better encapsulated data to improve a method of reusability, and robustness of the program, not a good place to be is the packaging process requires additional processing time.
Encapsulated object like a black box, which has a state object, and identification methods. It is left outside the inlet specific state object.
Including inheritance relationships between objects, polymerization, depending, interface, etc.
Here Insert Picture Description

Predefined classes

And the object variable c ++ similar object pointer, points to the address stored in the object heap memory.
java class contains time data and calendar localdata two objects to distinguish different problems
accessor method calls only state without changing the subject to generate a new object state, change is the method changes the original object status

Custom Class

The constructor is equivalent to the original function, but not to the same name as instance variables defined within the constructor will result in instance variables can not be initialized. Constructor features:
a: the same name as the name of the class constructor
II: receiving a plurality of configuration parameters (0 or more)
three: the new structure can be used only to validate the
four: no return value Constructor

The method includes displaying an object parameters and implicit parameter, the parameter refers to a method accepted parameters, a hidden parameter refers to an object invoke a method can be used to point to this.

In some cases, we need to get or set the value of an instance field. Therefore, it should provide the following three elements:
• a private data field ;
• a publicly owned domain accessor methods ; (Do not pay attention to the method returns a reference value, this would undermine the privacy of the data, if required returns a reference, you need to use clone method)
• a public domain of change control method .

/ Mutual access to the private data between objects of the same class , C ++ have the same principles. The method belongs to the class of private access characteristic (feature), but is not limited to private property access implicit parameter /

Four modifications keyword class
public: any class of any method to invoke this method or instance attributes;
Private: class has methods to modify and access to the private data of the same object , indicating that the data belongs to the class or method, or the same way the industry can access the private data . Examples of markers is not recommended public domain, the method allows all public line access and modify data stack;

Most final modifier applied to the base (primitive) type domain, or invariable domain (the immutable) class (if class
each object is a method which does not change, this class is immutable class. For example, String class is an immutable
class). CONST constant similar keywords unmodifiable basic variable values and can not be modified reference pointer.

Published 15 original articles · won praise 1 · views 137

Guess you like

Origin blog.csdn.net/qq_17236715/article/details/103621155