. GetClass ();

Source: Internet
Author: User

Each class in Java comes with a runtime class object that holds all the information needed to create the object.
You can use. class to return the runtime class object of this object, or it can be obtained using getclass ().
This object can be obtained by taking advantage of some of the reflection characteristics of this class object.
For example:
This.getclass (). newinstance (); Create an object of this class with the default constructor
This.getclass (). Getinterfaces (); Get interface information for this type of implementation
This.getclass (). GetMethods ();//Get all public methods for this type of implementation

Class.forName ("... JDBC Driver class name .... "); Class static method forname, register this JDBC driver class with Divermanager

GetClass () is a method in the object class that is used to get the class itself (after obtaining the class itself, you can use the Newinstance () method for instance).
Class person{
}
public class personclassdemo{
public static void Main (string[] args) {
Person per = new person ();
System.out.println (Per.getclass (). GetName ());
}
}
The result returned by the code above is the path to the package. class that the person object belongs to.
There are two other ways to get class,
1, "Class. Class" form, such as Person.class.
2, through the class of static method "Class.forName (" package. Classpath ")".

. GetClass ();

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.