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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Where can I find jdk in my computer?
Which package is used for pattern matching with regular expressions?
How to make a class immutable?
Is void a wrapper class?
what is the J2EE BluPrints?
What are E and PI?
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()); } }
What is the function of static in java?
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?
What is charat java?
How do you execute a thread in java?
what are the disadvantages of indexes in oracle?
0 Answers 3i Infotech, Wells Fargo,