Java Object-oriented (base) Knowledge Point summary I__java

Source: Internet
Author: User

1, class and object difference, class is an object template, object is a class instance

2, create the syntax of the class class name {}, the class is composed of properties and methods

3, the creation of the syntax of the object:

·     Declaring object: Class Name Object name = NULL; Equivalent to declaring an object name in the stack memory space, which is actually the address of the saved heap

• Instantiate object: Object name = new class name (); To open up the heap of memory space, the heap is stored in all the attributes

· The reference passing between classes actually conveys the right to use the heap memory space

· If an object is declared but not instantiated, a null-pointing exception appears when used

· Garbage object generation: Useless memory space, no stack memory pointing, and a stack memory can only point to a heap memory space

4, Encapsulation: The contents of the class is not visible to the outside

· The Private keyword can now be used to implement encapsulation in Java, but the encapsulated attributes can only be set and obtained by the setter and Getter methods

· In the design of a class, all attributes are required to be encapsulated. This is a standard design principle.

5. Construction method

· A construction method exists in any class

· Construction method name is consistent with class name, no return value type

· The construction method is invoked automatically when the object is instantiated using the keyword new

· If there is no explicit declaration of a constructor in a class, a parameterless constructor is automatically generated

6. String class

· String can be instantiated in two ways:

|-Direct assignment: It will only open up a heap of memory space

|-New Stirng (): will open two heap memory space, there is a garbage

· Once the contents of a string are declared immutable, the change is only to the point where the memory address

· A string is an anonymous object of a string

· Several action methods are provided in the String class: substring (), ReplaceAll (), Split (), Length ()

7. This keyword

· Use this to represent the current object, the object that is currently manipulating the method

· Use this to invoke a property or method in a class

· Use this to call the constructor method, but it must be placed in the first row of the construction method

The two purposes of this keyword: ① refers to implicit arguments, and ② calls other constructors of that class.

8, Super keyword

Two uses: one is to call the superclass method, and the other is to call the superclass constructor.

This, super keyword is used in a similar way when calling a constructor. Can only appear as the first statement of another constructor

9, a class can receive its own reference to this class but this usage is only used in the object comparison one position

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.