Java Learning Essentials (i)

Source: Internet
Author: User

1.static initialization

The static member variable and the static statement block are executed sequentially when the class byte code corresponding to it is loaded. Such as:

Class.forName ("Test. Statictest ");

At this point, the static member variable in the Statictest class will be initialized and the static statement block will be executed.

2.protected access Rights

Protected corresponding properties and methods can be accessed by classes in the same package, subclasses can access protected properties and methods by reference to subclasses.

In fact, the subclass can inherit the parent class's protected property and method, when the subclass accesses the parent class's protected property and method through its own reference, it actually accesses

The properties and methods that the subclass inherits from itself. Thus, subclasses cannot access the protected property and method through a reference to the parent class. Such as:

Package father;

Public Class father{

protected void Run () {

}

}

Package son;

Public Class Son extends father{

public static void Main (string[] args) {

Father f = new Father ();

F.run ();//Compile error, cannot call parent class's protected method by reference of parent class

Son s = new Son ();

S.run ();//compilation succeeds, the protected method of the parent class can be called through a reference to the child class

}

}

3.finalize Research

When an object cannot be accessed, the system will determine whether the object's Finalize method has been executed, and if it has already been executed, the system will recycle the object;

The object is placed in the F-queue queue waiting for the Finalize method to be executed. When the method is executed, the system will determine whether the object can be accessed, and if so, the object is resurrected, otherwise

will be recycled.

Java Learning Essentials (i)

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.