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


Please Help Members By Posting Answers For Below Questions

Why is java multithreaded?

542


what is bmg file and how to create that files?what will it contailn?

1897


What is the main functionality of the remote reference layer?

1420


What is polymorphism and what are the types of it?

513


What are the differences between Java 1.0 and Java 2.0?

1681






Is linkedlist thread safe in java?

565


What is an argument java?

541


Does it matter in what order catch statements for filenotfoundexception and ioexception are written?

512


What is void data type?

582


What access modifiers can be used for methods?

563


Explain the concept of proper inheritance?

623


How many bits is a word?

571


Can there be an abstract method without an abstract class?

541


What are byte codes?

659


When is the garbage collection used in Java?

658