• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

super . super

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
cowbird
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic