复制代码
- //:ToyTest.java
- //TestingclassClass
- interfaceHasBatteries{}
- interfaceWaterproof{}
- interfaceShootsThings{}
- classToy{
- //Commentoutthefollowingdefault
- //constructortosee
- //NoSuchMethodErrorfrom(*1*)
- Toy(){}
- Toy(inti){}
- }
- classFancyToyextendsToy
- implementsHasBatteries,
- Waterproof,ShootsThings{
- FancyToy(){super(1);}
- }
- publicclassToyTest{
- publicstaticvoidmain(String[]args){
- Classc=null;
- try{
- c=Class.forName("FancyToy");
- }catch(ClassNotFoundExceptione){}
- printInfo(c);
- Class[]faces=c.getInterfaces();
- for(inti=0;i<faces.length;i++)
- printInfo(faces[i]);
- Classcy=c.getSuperclass();
- Objecto=null;
- try{
- //Requiresdefaultconstructor:
- o=cy.newInstance();//(*1*)
- }catch(InstantiationExceptione){}
- catch(IllegalAccessExceptione){}
- printInfo(o.getClass());
- }
- staticvoidprintInfo(Classcc){
- System.out.println(
- "Classname:"+cc.getName()+
- "isinterface?["+
- cc.isInterface()+"]");
- }
- }///:~
复制代码
- Classname:FancyToyisinterface?[false]
- Classname:HasBatteriesisinterface?[true]
- Classname:Waterproofisinterface?[true]
- Classname:ShootsThingsisinterface?[true]
- Classname:Toyisinterface?[false]
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |