If a subclass provides a specific implementation of a method that is already provided by its parent class,
it is known as Method Overloading - Answers False
Correct the following code
public class D {
private double mass;
D() {
this(10.);
System.out.println("No-arg constructor");
}
D(double mass){
System.out.println("Constructor");
mass = mass;
}
public double getMass() {
return mass;
}
public void setMass(double mass) {
D.mass = mass;
}
} - Answers public class D {
private double mass;
D() {
this(10.);
System.out.println("No-arg constructor");
,}
D(double mass){
System.out.println("Constructor");
this.mass = mass;
}
public double getMass() {
return mass;
}
public void setMass(double mass) {
this.mass = mass;
}
}
What is the output of the following statements:
Truck mycar = new Truck();
System.out.println(mycar);
if we have the following classes:
public class Car {
public void m1() {
System.out.println("car 1");
}
public void m2() {
System.out.println("car 2");
}
, public String toString() {
return "general car";
}
}
public class Truck extends Car {
public void m1() {
System.out.println("truck 1");
}
} - Answers general car
Match each code fragment to the correct type of relationship
class Truck{
Engine engine;
Truck(){
Engine engine = new Engine();
engine.start();
}
} - Answers Composition
class Truck{
Engine engine;
Truck(Engine engine){
this.engine = engine;
engine.start();
}