日期:2014-05-20 浏览次数:20879 次
class Supclass {
}
public class TestClass extends Supclass {
public static void main(String[] args) {
Class clazz = TestClass.class;
Class class1 = Supclass.class;
System.out.println(class1.isAssignableFrom(clazz));
if (class1.isAssignableFrom(clazz)) {
System.out.println("Supclass是TestClass的父类");
} else {
System.out.println("Supclass不是TestClass的父类");
}
}
}
package linearStruct;
public interface TestInterface {
}
class subclass implements TestInterface {
public static void main(String[] args) {
Class clazz = subclass.class;
Class class1 = TestInterface.class;
System.out.println(class1.isAssignableFrom(clazz));
if (class1.isAssignableFrom(clazz)) {
System.out.println("TestInterface是subclass的父类");
} else {
System.out.println("TestInterface不是subclass的父类");
}
}
}