Can a subclass also be a superclass?

Can a subclass also be a superclass of another subclass in Java? Perhaps this is not the best example, but consider the following classes:

public class Animal { }
public class Dog extends Animal { } 
public class Cat extends Animal { } 
public class Siamese extends Cat { }
public class JackRussel extends Dog { }

Does inheritance allow for this sort of behaviour?

Given that JackRussels would require the methods and properties of both an Animal and a Dog, and Siamese’s would require the methods and properties of both Animal and Cat.

If not, is there a generalised approach I could take to achieve this sort of behaviour?

Cheers


Source: oop

Leave a Reply