Which answer fails to compile?

Given the following class declarations:
public abstract class Animal
public interface Hunter
public class Cat extends Animal implements Hunter
public class Tiger extends Cat
Which answer fails to compile?

Given the following class declarations:
public abstract class Animal
public interface Hunter
public class Cat extends Animal implements Hunter
public class Tiger extends Cat
Which answer fails to compile?

A.
Option A

B.
Option B

C.
Option C

D.
Option D

E.
Option E



Leave a Reply 5

Your email address will not be published. Required fields are marked *


renko

renko

Which answer fails to compile?
Only option E compiles!

Snr DingDong

Snr DingDong

Option D is the only one that causes issue. A cat object cannot be converted to a tiger object as it is its superclass.
(A Tiger “is a” cat but a Cat is not a Tiger)

In other words
Cat c = new Cat();
Tiger t = new Tiger();
// passing c into a t reference will not work
t = c; // will cause compilation error a Cat obj cannot be converted to Tiger