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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super . super" Watch "super . super" New topic
Author

super . super

sarada konda
Greenhorn

Joined: Dec 10, 2004
Posts: 7
class A
{
public void method1()
{
System.out.println("A"):
}
}

class B extends A
{
public void method1()
{
System.out.println("B");
}
}
class C extends B
{
public void method1()
{
super.method1();// but here i want call class A's method1
}
}

thanks in advance
Jef Cumps
cowbird
Ranch Hand

Joined: Nov 14, 2001
Posts: 53
Hi,

In Java, you're not allowed to call super.super. Childs have acces to their parents, but not to their grandparents...

Why would you need to call a method in the grandparent-class? Maybe this problem points you to e design that could be better? If C needs the implementation of A, couldn't it be a direct child of A then?
mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
hi SARADA,
This might be helpful to you


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

class B extends A
{
public void method1()
{
A a1;
a1 = new B();
super.method1();
System.out.println("B");
}
}

class C extends B
{
public void method1()
{
super.method1();// but here i want call class A's method1
}
}

class GrandCall
{
public static void main( String str[] )
{
A a2 = new A();
A b1 = new B();
A c1 = new C();

c1.method1();
}
}

If u want to print only A then right code in B's method
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super . super