class A{
m2(){
}
}
class B extends A{
m2(){
}
}
class c extends B{
m2(){
}
}
class my_class extends c{
m2(){
}
pulic static void main(){
...My_class a = new my_class();
super.super.super.m2(); is this is leagal
if not find what is the legal procedure in order to call A's
version of m2();
}
Answer Posted / n. bala subramanian
By reflection we can achive it, I hope this is correct
class A{
void m2(){System.out.println("in class A");}
}
class B extends A{
void m2(){System.out.println("in class B");}
}
class C extends B{
void m2(){ System.out.println("in class c");}
}
public class Test extends C {
void m2(){System.out.println("in class A"); }
public static void main(String[] args) throws Exception{
Class c = Class.forName("com.samples.test.Test");
A obj = (A) c.getSuperclass().getSuperclass
().getSuperclass().newInstance();
}
}
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is a double vs float?
Why is the singleton pattern considered to be an anti pattern?
What is thread safe singleton?
What is append function?
Why is java architectural neutral?
What does business logic mean?
What is split return?
What is the maximum size of arraylist in java?
Difference between error and exception
Differentiate between the constructors and methods in java?
What is the difference between the final method and abstract method?
What do you mean by jjs in java8?
Explain working of call by reference function invoking.
Can an interface extend a class?
What do you know about the garbate collector?