- class Toy{
- }
- class FancyToy extends Toy{
- }
- public class test{
- public static void main(String[] args) throws Exception{
- Class<FancyToy> ftClass = FancyToy.class;
- FancyToy fancyToy=ftClass.newInstance();
- Class<? super FancyToy> up = ftClass.getSuperclass();
- //Class<Toy> up2= ftClass.getSuperclass();//谁能解释不可以这样做?ftClass基类不就是Toy吗?
- Object obj=up.newInstance();
- }
- }
复制代码 |