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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
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 1 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 ?    2 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
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is the difference between AWT and SWING what is the advantage of using swing?  2
What is cloneable interface?  3
How can you take string into InputStream?  3
what is difference betwwen hashmap and hashtable ? Fidelity5
What is the exact difference in between Unicast and Multicast object ? Accenture1
why abstract class will have a constructor?  2
What is Remote Interface ? CTS2
What is exception and error? and what is the difference between them?  2
What are concepts of OOPS and how are they implemented in Java? KPIT2
what is the difference between Cpp And Java Infosys3
can we add two numbers without using arthematic operators? if possible how?  1
What is thin driver and thick driver. why it is called so? Logisoft1
Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?  1
What is I/O Filter? TCS1
What are the OOPS concepts in Java ? Satyam2
What we have to do, when we don't want to implement all methods of an interface?  2
What is a deadlock ?  4
can we create a instance for intwerface?  2
what is hashmap& hashtable with example? CTS1
Describe inheritance as applied to java?  4
 
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