Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 7

Given:

And given the code fragment:

What is the result?

    Correct Answer: A

    The given code correctly uses the `super` keyword in the `Car` class's constructor to initialize the `Vehicle` class part of a `Car` object. The default values for `type` and `maxSpeed` fields in the `Vehicle` class are used when the no-argument constructor of the `Vehicle` class is called implicitly. Therefore, the result of the fragment is '4W 100 Auto' for the first instantiation and '4W 150 Manual' for the second instantiation, making the correct answer '4W 100 Auto 4W 150 Manual'.

Discussion
miankitaOption: A

Answer is A. Child class constructors automatically called parent class one.

RoxyFoxyOption: A

No compilation errors. I tested the code and the correct answer is A: "super()" and "this" were used correctly in the constructors.

carlosworkOption: A

Answer is A. To test: package teste; class Vehicle{ String type = "4W"; int maxSpeed = 100; Vehicle(String type, int maxSpeed){ //Construtor da classe Pai this.type=type; this.maxSpeed=maxSpeed; } Vehicle(){} // Construtor Default } // fim da classe Vehicle public class Car extends Vehicle{ String trans; Car(String trans){ //line n1 this.trans = trans; } Car(String type, int maxSpeed, String trans){ super(type, maxSpeed); //line n2 this.trans = trans; } public static void main(String[] args) { Car c1=new Car("Auto"); Car c2=new Car("4W", 150, "Manual"); System.out.println(c1.type + " " +c1.maxSpeed + " " + c1.trans); System.out.println(c2.type + " " +c2.maxSpeed + " " + c2.trans); } // Fim da main } // Fim da class Car

Philip0908Option: A

This should be A!

samarrrrOption: A

instance variable can be inhertited , if the subclass dosent have the value ( variable ) the default it s not 0 or null , it s her superclass values

willokansOption: A

Answer is A No compilation fail c1.type and c1.maxSpeed have default values assinged to them in the Vehicle class. calling c1.type will fetch the Vehicle.typevalue of "4W" calling c1.maxSpeed will fetch the Vehicle.maxSpeed value of 100

Def8Option: A

No compilation errors. Answer is A.

Ancient1Option: A

Answer: A Tested: Yes Notes: No issue of compilation in this case. Both c1 and c2 are calling super constructors (c1 is using an implicit call), which are defined properly.

9de58b9Option: A

Tested

andradaraduOption: E

It is going to complain you're not overriding the parent constructor. Answer's E.

arjunrawatirissoftwareOption: A

Answer -A

a_really_reliable_programmerOption: A

Tested.

a_really_reliable_programmer

class Vehicle { String type = "4w"; int maxSpeed = 100; Vehicle(String type, int maxSpeed) { this.type = type; this.maxSpeed = maxSpeed; } Vehicle() {} } class Car extends Vehicle { String trans; Car (String trans) { //line n1 this.trans = trans; } Car(String type, int maxSpeed, String trans) { super(type, maxSpeed); // line n2 this.trans = trans; } } public class q7 { public static void main(String[] args) { Car c1 = new Car ("Auto"); Car c2 = new Car ("4W", 150, "Manual"); System.out.println(c1.type + " "+ c1.maxSpeed + " " + c1.trans); System.out.println(c2.type +" " +c2.maxSpeed + " "+c2.trans); } }

mbnsOption: A

Who determines that the correct anwers is E? It is obviously A. I have tested.

mrstevebangOption: A

My answer is A

Vicky_65Option: A

Answer is A

kkaayyyyOption: A

Answer is A

Faizal78Option: C

child class must have a matched parent constructor or calling parent construction as in n2