对Class类的理解:Class类包含了类的信息,如构造方法、方法、属性,可用于反射。以下是所有方法

获取class 信息  java

 

取Class类对象的几种方法:

Test test = new Test();

(1).test.getClass();

     在运行时确定,所以运行实例才是该类对象。super.getClass()不能获得父类的类对象,仍然是当前类对象。

     获得父类类对象: test.getClass().getSuperclass()

class Father{
    public void showName()
    {
         System.out.println("Father...");
    }
}
 
class Child extends Father{
    public void showName()
    {
         System.out.println("children");
    }
}
 
Father father = new Child();
System.out.println(Father.class);      结果是 Father

  

 

相关文章:

  • 2021-10-10
  • 2021-05-29
  • 2022-12-23
  • 2022-01-24
  • 2021-09-02
  • 2022-01-20
  • 2021-08-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2021-08-29
  • 2022-02-12
  • 2021-07-16
  • 2021-08-18
  • 2021-06-17
相关资源
相似解决方案