Answer:
2
Explanation:
The output of the Java program is 2. The public Vehicle class is defined with the class variable 'counter'. When a Vehicle class object is instantiated, the counter variable increments by one.
In the program, the two instances of the class are created, incrementing the counter variable to two, the print statement outputs 2 as the result of the program.
Answer:
Explanation:
The following code is written in Java. I recreated the entire Child class as described with the instance variables and the doubleWeight method. Then created the getter and setter methods for both the weight and height variables.
class Child {
double weight, height;
public double doubleWeight() {
double superWeight = weight * height;
return superWeight;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
If you have only 1 method that is not overloaded, then you will not be able to call it with inappropriate parameter types, that is, if the initial type of the parameter is int, then it will not be able to get the double, float, and other values, because of this an error will occur.
For this, method overloading is created.
Method overloading is when you create methods with the same name, but only the content and parameters of the methods are/can-be completely different.