aspose file tools*
The moose likes Beginning Java and the fly likes Calling super-to-superclass members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling super-to-superclass members" Watch "Calling super-to-superclass members" New topic
Author

Calling super-to-superclass members

saxena vicky
Greenhorn

Joined: Sep 05, 2005
Posts: 18
How can I call the method of Class A1 from C1


public class A1 {

public void method()
{
System.out.println(" A1 ");
}
}

public class B1 extends A1{
public void method()
{
System.out.println(" B1");
}
}

public class C1 extends B1{
public void method()
{
super.method();// This will call the method of B1 class
//How can I call the method of Class A1 from C1
System.out.println(" C1");
}
}

swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

There is no way you can directly refer to super-super class's instance method if both the super and super-super class of the sub class have instance method with same signature...
But still there is way you can manage it in your code..better if you figure it out yourself...keep trying, keep thinkin ...

saxena vicky wrote:How can I call the method of Class A1 from C1


public class A1 {

public void method()
{
System.out.println(" A1 ");
}
}

public class B1 extends A1{
public void method()
{
System.out.println(" B1");
}
}

public class C1 extends B1{
public void method()
{
super.method();// This will call the method of B1 class
//How can I call the method of Class A1 from C1
System.out.println(" C1");
}
}

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
You asked a new question on this old thread. I don't think it is a good idea to add new questions to old thread. Fortunately, we have a new technique for removing new posts from threads, which I am trying out. I've never used it before. Your posts are now here.
saxena vicky
Greenhorn

Joined: Sep 05, 2005
Posts: 18
Thanks for the reply swaraj.

But please tell me how can I call the overridden method of Class A1 from the method in Class C1
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

You can't. And if you think you need to do that, you're grossly misusing inheritance.


luck, db
There are no new questions, but there may be new answers.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

A class can only call it's super class methods. Nothing above can be called (except for static methods of course).


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling super-to-superclass members
 
Similar Threads
how to use super
Method Invocation
about overloading
super . super
help needed on Inner classes program