1z0-808 Exam QuestionsBrowse all questions from this exam

1z0-808 Exam - Question 7


Given:

And given the code fragment:

What is the result?

Show Answer
Correct Answer: AE

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

17 comments
Sign in to comment
RoxyFoxyOption: A
Sep 21, 2022

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

miankitaOption: A
Dec 20, 2022

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

Philip0908Option: A
Sep 5, 2022

This should be A!

carlosworkOption: A
Oct 31, 2022

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

Ancient1Option: A
Sep 6, 2022

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.

Def8Option: A
Oct 28, 2022

No compilation errors. Answer is A.

willokansOption: A
Nov 22, 2022

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

samarrrrOption: A
May 6, 2023

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

Faizal78Option: C
Sep 4, 2022

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

kkaayyyyOption: A
Sep 9, 2022

Answer is A

Vicky_65Option: A
Apr 1, 2023

Answer is A

mrstevebangOption: A
Apr 27, 2023

My answer is A

mbnsOption: A
Jul 25, 2023

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

a_really_reliable_programmerOption: A
Aug 21, 2023

Tested.

a_really_reliable_programmer
Aug 21, 2023

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

arjunrawatirissoftwareOption: A
Oct 11, 2023

Answer -A

andradaraduOption: E
Nov 3, 2023

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

9de58b9Option: A
May 9, 2024

Tested