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 / ranganathkini

No it is illegal to call:

super.super.super.m2();

If the implementation of m2() defined by class A has to be
called from within my_class's implementation of m2(), the
following change must can be made:

class A {
public void m2() {
// call the protected implementation
m2Impl();
}

// a protected implementation of A's m2() method
// giving the implementation a protected access
// allows only subclasses to see the method
// and remains inaccessible to the rest of the world
protected void m2Impl() {
System.out.println( "A.m2() invoked" );
}
}

class B extends A {
public void m2() {
System.out.println( "B.m2() invoked" );
}
}

class C extends B {
public void m2() {
System.out.println( "C.m2() invoked" );
}
}

class my_class extends C {
public void m2() {
// call A's protected implementation
m2Impl();
}
}

public class TestSuperSuper {
public static void main( String[] args ) {
my_class mc = new my_class();
mc.m2();
}
}

Hope it helps! :-)

Is This Answer Correct ?    10 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the simpletimezone class in java programming?

1132


Explain the difference between private, public, package and protected in java?

1044


Name and explain the types of ways which are used to pass arguments in any function in java.

1079


What is the purpose of abstract class?

1017


What is int short for?

1051


What is append in java?

1166


What is the difference between serializable and externalizable interfaces?

1100


What is unicode with example?

1215


How do you sort a string in alphabetical order in java?

919


What is the difference between jdk, jre, and jvm?

1119


Which number is denoted by leading zero in java?

1244


What is a parameter used for?

963


What is string intern in java?

1025


Does treeset allow null in java?

957


What is quick sort in java?

1015