0
class a { void show() { } class b extends a { void show() { } class c extends b { //how to call show method of class a } } } 

Does anyone know how I can call method of class a from class c using super keyword

2
  • Please format that code. Also, what language are you using? Assuming pseudocode, I would say that "show()" should be inherited to class "C", so it should be callable anyway. Assuming that "show()" in class "A" is private, it depends on the language - assuming C#, there would be no way to call it from class "A" (since the method is private). Commented Feb 19, 2015 at 9:41
  • Seems duplicate: stackoverflow.com/q/11935895/11226492 stackoverflow.com/q/586363/11226492 Commented Jan 29, 2024 at 2:30

1 Answer 1

1
class A { void show() { System.out.println("A"); } } class B extends A { void show() { System.out.println("B"); } } class C extends B { void show() { super.show(); } } 

The above code will display "B" when class C object is invoked. In your case, there can be 2 options:

  1. C extends A - This will let super.show() in show method of class C display "A".
  2. Add super.show() in show method of class B so that show method of class C displays both "B" and "A".

There is no way to call super class methods which are higher than level 1.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.