Java Object-oriented one

Source: Internet
Author: User

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

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.