标签:print 通过 new str pac 方式 except pre 获取
获取Class对象的三种方法
package com.first;
public class Demo {
public static void main(String[] args) {
Dog dog = new Dog("花花",10);
//方式一,通过对象获取class对象
Class<? extends Dog> aClass = dog.getClass();
//方式二,通过类来获取
Class<Dog> dogClass = Dog.class;
//方式三,通过Class.forName;
try {
Class.forName("com.first.Dog");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
class Dog{
private String name;
private int age;
public Dog(String name, int age) {
this.name = name;
this.age = age;
}
}
标签:print 通过 new str pac 方式 except pre 获取
原文地址:https://www.cnblogs.com/yanxiaoge/p/10745384.html