Is it possible in java to inherit some methods from the base class, but not all of them? Just to be clear, i will show you what I mean: Suppose we have the base class Visitor
public abstract class Visitor {}
From Visitor we create 2 more Objects, Client and Companion:
public class Client extends Visitor {}
public class Companion extends Visitor {}
In Client, we create the method:
boolean has_Companion() {}
In order to achieve runtime polymorphism, we need to declare the method in Visitor as well:
abstract boolean has_Companion();
The problem is that since we declare the method in Visitor, Companion inherits it as well. We don't want that. When I compile I get the following error:
The type Companion must implement the inherited abstract method Visitor.has_Companion()
There is no point in implementing the method has_Companion() for Companion because it will never be used. It's a waste of code. Can I avoid it in some way? Can the method has_Companion() be inherited only by Client, and not by Companion?