Ask Question

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 ();

+4
Answers (1)
  1. 5 November, 22:40
    0
    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 ();

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Consider the following classes: public class Vehicle { ... } public class Car extends Vehicle { ... } public class SUV extends Car { ... } ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers