public class test1 {
public static void main(String[] args)throws Exception {
Class<?> cls = Class.forName("demo6.Book");
Book book = (Book)cls.newInstance();
book.setTitle("JAVA");
book.setPrice(32);
System.out.println(book);
}
}
Exception in thread "main" java.lang.InstantiationException: demo6.Book
at java.lang.Class.newInstance(Unknown Source)
at demo6.test1.main(test1.java:8)
Caused by: java.lang.NoSuchMethodException: demo6.Book.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 2 more
12345678_0001
相关分类