Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is void a type?

930


Is binary a low level language?

871


What is lexicographically smallest string?

1018


What are the differences between stringbuffer and stringbuilder?

1001


Tell me the Importent classes in net package?

1950


I don’t want my class to be inherited by any other class. What should I do?

967


Explain the usage of this with constructors?

976


What do you mean by singleton class in java?

856


Is it possible to compare various strings with the help of == operator? What are the risks involved?

1023


What is string [] args?

957


What is the final keyword in java?

1354


What is the default value of byte datatype in java?

880


What are internal and external variables?

908


Is it correct to say that due to garbage collection feature in java, a java program never goes out of memory?

970


Can you achieve runtime polymorphism by data members?

1076