ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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();

}
 Question Submitted By :: Praveencarasala
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    1 Yes 1 No
Ranganathkini
 
  Re: 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
# 2
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 ?    0 Yes 2 No
Priynajan
 
 
 
  Re: 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
# 3
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 ?    0 Yes 2 No
Monika
 
  Re: 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
# 4
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 0 No
Kalpit
 
  Re: 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
# 5
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 ?    3 Yes 0 No
Santosh Subrahmanya
 
  Re: 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
# 6
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 ?    1 Yes 0 No
Sree
 
  Re: 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
# 7
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 ?    0 Yes 0 No
N. Bala Subramanian
 
  Re: 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
# 8
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 ?    0 Yes 0 No
Debapriya Maity
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
which class to use when concatenating strings in a loop. IBM2
types of applets?. TCS3
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(); } Logica-CMG8
How the elements are organized in BorderLayout?  4
What is the frontend and backedn in Java? TCS2
Hey buddy.. can you please tell me about the use of marker interface? And is there any link between marker interface and factory methods? Thanks in advance.  2
Why all programming languages have main as a execution starting point?  2
when we write class.forName("any one class"); what happens actually?what it will return?explain stepwise?  4
what Data encapsulation in java?  4
Need 2+ yrs experienced java techinical question papaer for company Iflex  1
how can u apply shallow cloning and deep cloning to create object? Yash-Technologies1
what is generics in jdk1.5? Bally-Technologies1
basic difference b/w ALL types of JDBC driver. Systematix1
steps to connect with Oracle Databse using TYPE-2 Jdbc driver.  1
As a developer what steps do you take to improve the performance?  3
What is exception and error? and what is the difference between them?  2
How Applets & Servlets will communicate with each other?  2
Is ResultSet class? Bally-Technologies2
Name the method that is used to set a TextComponent to the read-only state?  1
How can you say HashMap is syncronized? IBM13
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com