A little more java every day (3)

Source: Internet
Author: User

1. modifier of Class: Public (used in the same package) Abstract (no instance) Final (cannot be a parent class)

2. The object class includes the equals, clone, and tostring methods. String + this object, the tostring method is automatically called. The clone method allocates new memory space and copies the object by bit-by-bit in the space.

3. Java maintains a "run time type identification" that tracks the classes to which each object belongs. This ensures that the current method is selected accurately during runtime. The class that stores the relevant identity information is called the class. The getclass method of the object class can return an instance of the class. Getclass () returns the tostring () of the class type, and getname () returns the type name .. The class can only be used as a static variable and cannot be used as an instance variable.

Reprinted below:

Three methods for getting a class instance:

1) Call the getclass () method to obtain the class instance of the object.

2) use the static method forname () of the class to obtain a class instance with the class name.

3) use the. Class method to obtain the class instance. For the encapsulation class of the basic data type, you can also use. type to obtain the corresponding class instance of the basic data type. The keyword instanceof returns a Boolean value to determine if an instance of a specific type is used.

Class. newinstance () uses the selected class object to generate a new instance of this class. It calls the default (No parameter) Class constructor to generate a new object. Therefore, the class created using newinstance () must have a default constructor.

If a class object exists, you can use getsuperclass () to obtain its direct base class. This method also returns a class reference, so you can further query its base class. This means that a complete class hierarchy of an object can be found during the runtime.

Example:

Class Heihei {

}

Class Haha {

Public static void main (string ARGs []) {

Heihei Hoho = new Heihei ();

// System. Out. println (hoho. Class );

System. Out. println (hoho. getclass ());

System. Out. println (hoho. getclass (). getname ());

// System. Out. println (hoho. Class. getname ());

System. Out. println (Heihei. Class. getname ());

System. Out. println (Heihei. Class );}}

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.