class A extends Object {
public void xxx() {
System.out.println("A");
}
}
class B extends A {
public void xxx() {
System.out.println("B");
}
}
class C extends B {
public void xxx() {
// call A.xxx();
//方法一 new A().xxx(); //方法二
Class clazz = Class.foName("A");
Object object = clazz.newInstance();
Method mothod = clazz.getDeclaredMethod("xxx");
mothod.invoke(object);
乱写一通,哈哈{:2_36:}
public static void main(String[] args) {
C c = new C();
c.print();
}
}
class A{
public void print(){
System.out.println("A");
}
}
class B extends A{
public void print(){
System.out.println("B");
}
}
class C extends B{
public void print(){
// System.out.println("C");
Class cclazz = C.class;
String name = cclazz.getSuperclass().getSuperclass().getName();//获取父类的父类类名
System.out.println(name); //打印出类名
com.heima.me.A a = new com.heima.me.A(); //然后创建对象
a.print(); //调用父类的父类中最初的方法
}
}