public static void main(String[] args) {
Vehicle y = new Car();
System.out.println(y);
}
}
Output:
Exception in thread “main” java.lang.Error: Unresolved compilation problem:
Constructor call must be the first statement in a constructor
at q066.Car.(Car.java:7)
at q066.Car.main(Car.java:18)
Answer D:
package q066;
public class Vehicle {
int x;
Vehicle() {
this(10); //line n1
}
Vehicle(int x) {
this.x = x;
}
}
package q066;
public class Car extends Vehicle {
int y;
Car() {
super();
this(20); //line n2
}
Car(int y) {
this.y = y;
}
public String toString() {
return super.x + ” : “+ this.y;
}
public static void main(String[] args) {
Vehicle y = new Car();
System.out.println(y);
}
}
Output:
Exception in thread “main” java.lang.Error: Unresolved compilation problem:
Constructor call must be the first statement in a constructor
at q066.Car.(Car.java:7)
at q066.Car.main(Car.java:18)
D