144k views
5 votes
Consider the following classes: public class Vehicle {...} public class Car extends Vehicle {...} public class SUV extends Car {...} Self-Check Problems 617 Which of the following are legal statements? a. Vehicle v = new Car(); b. Vehicle v = new SUV(); c. Car c = new SUV(); d. SUV s = new SUV(); e. SUV s = new Car(); f. Car c = new Vehicle();

User Feech
by
4.1k points

1 Answer

4 votes

Answer:

Legal statements:

SUV s = new SUV();

Car c = new SUV();

Vehicle v = new SUV();

Vehicle v1 = new Car();

illegal statements:

SUV s1 = new Car();

Car c1 = new Vehicle();

Step-by-step explanation:

The options a, b, c, d are correct and legal statements because the syntax is correct, they follow the inheritance principles and therefore can be used for type cast.

The options e, f are incorrect and illegal statements because they do not follow the inheritance principles and therefore can not be used for type cast.

User Rszalski
by
5.0k points