Answer:
Check the explanation
Step-by-step explanation:
Q1 ) class Animal is the superclass, as the Cat class is inherited from Animal class
and the class Cat is the subclass.
The statement class Cat extends Animal means that, the class Cat is inherited from class Animal and class Cat has all variables and methods defined in class Animal (except private variable and methods).
Q2 ) The class Cat cannot directly access the fields it inherits from Animals, because of all the fields in class Animals are private and the extend keyword-only make the public fields accessible through the Cat class.
Q3 )
public Cat(String name, boolean isShortHaired) //constructor with 2 parameters String and boolean
{
super(name,3); //calling constructor of super class,with fields
this.isShortHaired = isShortHaired;
}
Q 4)
public String toString() //to string method
{
if(isShortHaired == true)
return super.toString+" (Short Haired) "; //returns name (Short Haired)
else
return super.toString+" (Long Haired) "; //returns name (Long Haired)
}
Q 5)
public boolean isSleeping (int hour, int minute) //overriding isSleeping method of super class
{
if (hour > 24 || hour <0 || minute > 60 || minute < 0) {
throw new IllegalArgumentException ("invalid timespecified");
}
return true; //returning true for all the valid time entered
}