Object-oriented < basic > Knowledge points

Source: Internet
Author: User

1 An object that is not instantiated is used to appear java.lang.NullPointException

21 Stacks of memory space can only point to a heap memory space, if you want to point to other heap memory space, you need to first break the current point

3 as long as the encapsulated attribute must be set and obtained through the Gette/setter method

4 An anonymous object is an object that does not explicitly give a name. Generally anonymous objects are used only once, and anonymous objects only open space in heap memory, and there is no reference to stack memory

In actual development, it is basically passed as a parameter of other instantiated objects.

5 = = is the comparison memory address,. Equals () comparison value

6 string after using direct assignment, the heap memory will not be newly opened as long as the string contents of the later life are the same

7 If new is used, it will open up a space anyway.

81 changes to the contents of a string object are performed on the machine by a disconnected-connection of the memory address, the string itself does not change

91 pairs of relationships, such as books and people two classes, there is a property in the human book, the book class should also have an attribute person

10 in some complex systems, in order to better describe the relationship between classes, often in the entity has been set, the entity was a separate entity, such as books and human

All this: the methods in this class, the properties in the class, can call the constructor method of this class, the current object represented by the

When you call the constructor method, there is at least one constructor method in the program that does not use this ()

This indicates that the current object is the object that called the method containing this, and this represents the object

14 compare two objects, first compare memory addresses, then compare each property

Static: If some properties want to be shared by all objects, you use static to set the Statics (global) property

16 after setting the static property, any object modifies this property, and all other objects are also modified synchronously

The memory areas commonly used in Java:

Stack memory: The address of the heap memory space that is referenced by saving the object name

Heap Memory: Save specific property content for each team

Global Data area: Saving properties of static type

Global Code Area: Save All method definitions

18 calling the static property is best with a class. The static property is Person.country = "XXX" Country is a static property

Static can also be modified method, called the same way

20 non-static methods can invoke the properties and methods of the static declaration, but the methods and properties of a static declaration cannot be called by a method that is not static

The static property is shared by all objects, so you can use the static property to count how many objects this class produces

Example:

1  Public classClassdemo {2 3     Private Static intCount = 0;4 5      PublicClassdemo () {6count++;7System.out.println ("generated" + Count + "objects");8     }9 Ten } One  A classstaticdemo{ -  -      Public Static voidMain (string[] args) { the         NewClassdemo (); -         NewClassdemo (); -         NewClassdemo (); -     } +  -}

22 Code blocks:

Common block of code: a block of code defined directly in a method or statement

Building blocks: Building blocks are better than construction method execution, and each instantiation executes

Static code block: a code block that uses the static declaration, if the static block of code is written in the class where the main function is located, then this code block takes precedence over the main method execution

Synchronizing code blocks: to be added

23 Construction method After privatization, declare a private static object in the class, and then Static getXxx () to get the object, the class can be used within the main function. GETXXX () Gets the object instance. No matter how many times the main function is declared, there is only one instanced object for the heap memory

That is, the singleton mode, no matter how the program is run, has only one instance of this constructor privatization class

As long as the construction method is privatized, it is possible to control the generation of instantiated objects

24 Object array: An array that contains multiple objects. An array must first open up space, but because the object is a reference data type, the current object of the array is null, using each object in the array but must instantiate the operation separately

25 static initialization and dynamic initialization

Static initialization of arrays
Int[] a={1,2,3,4};

Dynamic initialization
Int[] intarray;//Declaration array
Intarray = new int[5];//allocates space for array

The so-called static and dynamic is relative to the program runs, Static is initialized at the time of the program compile, dynamic initialization is the program run is to dynamically allocate memory space. In the case of code, you can actually. The only difference is that the dynamic initial value is 0, and the static value is given directly.

26 Inner classes: One benefit is that you can easily access private properties in an external class

27 an inner class that uses the static declaration becomes an external class, but it cannot ask for non-static external class properties

28 external access to the inner class's format: Outer class, Inner class inner Class object = External class instance. New inner class ();

Get an instance of an external class to create a

29 define inner classes in methods: This class cannot directly access the parameters in the method, and if the parameters in the method are to be accessed by an internal class, the parameter must be preceded by the final keyword

Object-oriented < basic > Knowledge points

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.