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();

}

Answers were Sorted based on User's Feedback



class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

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

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / santosh subrahmanya

This will work......

class A{
public void m2(){
System.out.println("called...");
}
}

class B extends A{
public void m2(){
super.m2();

}
}

class c extends B{
public void m2(){
super.m2();

}
}

class my_class extends c{
public void m2(){
super.m2();

}

public static void main(String[] args){

my_class a = new my_class();
a.m2();

}
}

Is This Answer Correct ?    10 Yes 2 No

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / sree

class A{
void m2(){

System.out.println("in class A"); }
}

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

class c extends B{
void m2(){super.m2();
System.out.println("in class c");
}
}

class Check extends c{
void m2(){
super.m2();
System.out.println("in check()"); }
public static void main(String[] args){
c obj =new Check();
obj.m2();
}
}

Is This Answer Correct ?    4 Yes 0 No

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

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

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / debapriya maity

First super keyword cannot be used from a stati
ccontext,this is the first thing to be remembered.The
correct procedure is

class A{
m2(){
super();
}
}
class B extends A{
m2(){
super();
}
}
class c extends B{
m2(){
super();
}
}
class my_class extends c{
m2(){
super();
}
pulic static void main(){
my_class a = new my_class();
a.m2():
}

}

Is This Answer Correct ?    1 Yes 1 No

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / kalpit

super.super.super.m2(); is illegal there can be only super.m2();

There is no way that A's m2 & B's m2 can be called using
object of my_class.

A obj =new A();
obj.m2();

is correct

Is This Answer Correct ?    0 Yes 1 No

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / monika

Above solution looks correct but it is not taking advantage
of inheritance.
I hope following code does the trick.

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");
}
}
class Check extends c
{
void m2()
{
System.out.println("in check()");
}
public static void main(String[] args)
{
A obj =new Check();
obj.m2();
}
}

Is This Answer Correct ?    2 Yes 4 No

class A{ m2(){ } } class B extends A{ m2(){ } } class c extends B{ m2(){ } } class my_cl..

Answer / priynajan

No it is not leagal the correct procedure is:
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");
}
}

class Check extends c{
void m2(){System.out.println("in check()"); }
public static void main(String[] args){
A obj =new A();
obj.m2();
}
}
..
Works correctly :-)

Is This Answer Correct ?    1 Yes 8 No

Post New Answer

More Core Java Interview Questions

Where can I find jdk in my computer?

0 Answers  


Which package is used for pattern matching with regular expressions?

0 Answers  


How to make a class immutable?

15 Answers   Bosch, TSYS,


Is void a wrapper class?

0 Answers  


what is the J2EE BluPrints?

0 Answers  


What are E and PI?

1 Answers  


What will be the output of the program? public class Test { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("2"); list.add("3"); list.add("4"); list.add("5"); System.out.println("size :"+list.size()); for(int i=0;i<list.size();i++) { list.remove(i); } System.out.println("size after:"+list.size()); } }

5 Answers   Rolta,


What is the function of static in java?

0 Answers  


Suppose there is an Online shopping cart application having different objects like Cart, SelectionItem, Billing, COnfiguration, Authentication, Authorization, PersonalDetails etc. Out of this which one can be made a singleton pattern and why?

2 Answers   RBS,


What is charat java?

0 Answers  


How do you execute a thread in java?

0 Answers  


what are the disadvantages of indexes in oracle?

0 Answers   3i Infotech, Wells Fargo,


Categories