1

Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C).

The answer to this question given at source is that it is not possible ,i am not able to understand why.I read the docs:https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Suppose we have a class Animal(class C), and class Canine(class B) extends it and class Dog(class A) extends Canine(class B).so if i want to invoke a method test() in class c why cant i do it?? According to inheritance when A extended B class it has all the methods of B as well as of C.Right?

Another example:

           public class MountainBike extends Bicycle {

              // the MountainBike subclass adds one field
               public int seatHeight;

            // the MountainBike subclass has one constructor
                public MountainBike(int startHeight,
                    int startCadence,
                    int startSpeed,
                    int startGear) {
                super(startCadence, startSpeed, startGear);
                seatHeight = startHeight;
            }   

           // the MountainBike subclass adds one method
            public void setHeight(int newValue) {
             seatHeight = newValue;
        }   
     }
azurefrog
  • 10,785
  • 7
  • 42
  • 56
  • "all the three classes implement the method test()." so all classes made their own implementation of `test()` method. To be more precise subclasses override this method. To invoke method from superclass you could call `super.test()` but you can't do `super.super.test()` in Java [Why is super.super.method(); not allowed in Java?](http://stackoverflow.com/questions/586363/why-is-super-super-method-not-allowed-in-java) – Pshemo Aug 08 '16 at 14:16
  • So you can only call methods from superclass, and superclass can invoke method from its superclass, but *directly* calling method from super-superclass is impossible and that is what this question was about. – Pshemo Aug 08 '16 at 14:21

0 Answers0