0

In Java, I have a class A which has a function say 'funA'. I have a subclass B which has again a function 'funA' which overrides it. And a class C which is a sublcass of B and has a function 'funA' which also overrides it. How can I access the function 'funA' from class C?

class A {   

 public void funA() {
    System.out.println("a in A...........");
 }
}
class B extends A {

 public void funA() {
     System.out.println("a in B...............");
 }

}

class C extends B { 
  //How to access 'funA' of A from here
}

2 Answers2

0

You can't, the class B overrides it. It would be possible only if the method in B had different signature than the method in A or if C extended directly class A.

This is very well described in Oracle's Java tutorial

Sva.Mu
  • 1,141
  • 1
  • 14
  • 24
0

You can't. This is not a good way to use inheritance. If B is not appropriate for C, don't extends it. For more detail about inheritance, please refer: https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Hope this help.

Kenny Tai Huynh
  • 1,464
  • 2
  • 11
  • 23