Given:
And given the code fragment:
What is the result?
A.
4W 100 Auto
4W 150 Manual
B.
Null 0 Auto
4W 150 Manual
C.
Compilation fails only at line n1
D.
Compilation fails only at line n2
E.
Compilation fails at both line n1 and line n2
Given:
And given the code fragment:
What is the result?
A.
4W 100 Auto
4W 150 Manual
B.
Null 0 Auto
4W 150 Manual
C.
Compilation fails only at line n1
D.
Compilation fails only at line n2
E.
Compilation fails at both line n1 and line n2
E
Test E.
E. n1 fails because you are only invoking 1 argument but you have to use 2, so fail. N2 fails because you cant use Super() and This() in the same object.
Answer is E.
Despite the IDE saying it needs two arguments. This fails to compile because unless you define it otherwise the jvm implicitly makes a call to super() as the first line in a constructor. So as there is no such constructor in class Vehicle compilation fails at line n1.
Line n2 fails due to super constructor and this constructors being called together.
easily fix both problems by creating a no argument constructor in class vehicle and removing the call to this() at line n2 and replacing with
this.trans = trans;