Question
I don't understand: what I think is that since SUV extends Car extends Vehicle, SUV should have the suv, car and vehicle constructors, Car should
I don't understand: what I think is that since SUV extends Car extends Vehicle, SUV should have the suv, car and vehicle constructors, Car should have the Car and vehicle constructors, and Vehicle should just have the vehicle constructor. So how come statements like the first one, which are calling a constructor in a subclass from a superclass, are legal? Shouldn't all the answers be flipped (except d)? class_name object_name = new class_name(); public class Vehicle {} public class Car extends Vehic le {} public class SUV extends Car {} 4. The following statements are marked as legal or illegal: a. Vehicle v= new Car();// legal b. Vehicle v= new SUV();// legal c. Car c = new SUV(); // legal d. SUV s= new SUV(); // legal e. SUV s= new Car(); // illegal f. Car c= new Vehicle( );// illegal
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started