question archive This is java programming: Assume that the following code compiles correctly in a client of the Car class: Car mustang = new Car("Ford", "Mustang", 2005); Car bronco = new Car("Bronco", 1994); What do you know about the Car class? I
Subject:Computer SciencePrice:2.87 Bought7
This is java programming:
Assume that the following code compiles correctly in a client of the Car class:
Car mustang = new Car("Ford", "Mustang", 2005);
Car bronco = new Car("Bronco", 1994);
What do you know about the Car class?
I. The Car class has at least two overloaded constructors
II. The year of the car is required to construct a Car object
III. Both the make and the model of the car are required to construct a Car object.
Statements 1 and II only
Statements I and III only
Statements II and III only
Statements I, II, and III
Statement I only
Answer:
statement 1 and 11 only.
in the above code, the two constructor compiles successfully
Car mustang = new Car("Ford", "Mustang", 2005);
Car bronco = new Car("Bronco", 1994);
So inside car class there must be two consturctor
Car(String make, String model,int year){
}
and another constructor will be as:
Car(String model,int year){
}
Car mustang = new Car("Ford", "Mustang", 2005); will use the first constructor
Car bronco = new Car("Bronco", 1994); will use the second constructor.
So it can be seen , Car class has two overloaded constructor , year is required in both the constructor so statement I and II are correct.
Whereas, only first constructor requires make , so Statement III is false.