The class class for Java

Source: Internet
Author: User

1  Packagetest;2 Importjava.util.Date;3  Public classSuperTestextendsdate{4     Private Static Final LongSerialversionuid = 1L; 5     Private voidTest () {6System.out.println (Super. GetClass (). GetName ()); 7     } 8       9      Public Static voidMain (String[]args) {Ten        NewSuperTest (). Test (); One     }  A}

The output is: test. SuperTest

Analysis:super.getClass() 得到的依然是runtime当前类,若要得到真正的父类,需要用super.getClass().getSuperclass()

虽然这里写的是 super ,但其实用 this 也一样The class class of Java is the basis of the Java reflection mechanism, and we can obtain information about a class through class classes. Java.lang.Class is a special class that encapsulates information that is loaded into a class (including classes and interfaces) in the JVM. When a class or interface is loaded into the JVM, it produces a Java.lang.Class object associated with it, which can be accessed through this class object for the details of the loaded class.

The class class for Java

Related Article

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.