Java object-oriented programming to organize a
three major features:
Package: Encapsulation
Inheritance: Inheritance
Polymorphic: Polymorphism
To create an object:
person per = null; declaring objects
per = new person (); Instantiating an Object
Or
Person per = new person (); Declaring + instantiating an object
The properties of the object are stored in the heap memory.
The method of the object is stored in the code area and is oriented globally.
NullPointerException is a common Java error that indicates that there is a null point.
one stack of memory can allocate multiple heap memory space
Such as:
person per1 = null;
person per2 = null;
Per1 = new Person ();
Per2 = Per1;
The contents of the Per1 change after the Per2 property is changed!
Private is the encapsulation of attributes, and he has a protective effect on attributes!
You cannot have a return value in a constructor method.
The constructor method is not called when the object is declared.
construction methods are not required
If a constructor is not explicitly declared in a class, the system automatically generates a constructor that does nothing without a parameter.
If you declare a constructor with parameters in the class, the system does not declare the parameterless construction method again.
construction methods can overload
As long as the constructor method has different parameter types or numbers, it can be overloaded.
Constructors and methods differ in the following three ways: modifiers, return values, naming.
1. As with methods, constructors can have any access to adornments: public, protected, private, or no adornments (usually called by the package and friendly). Unlike methods, constructors cannot have the following non-accessible adornments: abstract, final, native, static, or synchronized.
2. The return type is also very important. Method can return any type of value or no return value (void), the constructor has no return value, and no void is required.
3. The name of both. The constructor uses the same name as the class, and the method is different. By custom, methods usually start with lowercase letters, and constructors usually start with uppercase letters. A constructor is usually a noun because it is the same as the class name, and the method is usually closer to the verb because it shows an action.
Anonymous Objects
Is the lack of the use of the stack memory space to declare the object, that is, using the new person directly (). tell ();
design Analysis of Class
Java Object-oriented one