[Solved] Java: How to access implementation of a method of Sub class from Super class


Consider following:

public interface Animal {

    bool isVertebrate();
    bool isDomesticable();  
}

and an abstract class that implements this interface:

abstract class Cat implements Animal {

public bool isVertebrate() {return true;}

public void dealWithCat(){
if (isDomesticable()){
 ...
   }
}

But implementation for isDomesticable is delegated to subclass:

public class Tiger extends Cat {

public bool isDomesticable(){
return false;
}

Since Cat is abstract, it can’t be instantiated. It is free to provide implementation for some interface methods, but doesn’t have to provide it for every method. The methods that it doesn’t provide implementation for, must be provided by by subclass. And at run time, methods in super class get implementation from subclass. So in our example, implementation of isDomesticable() is not provided by Cat but it is later implemented by Tiger.

solved Java: How to access implementation of a method of Sub class from Super class