Question
Given the below class: public class Dog { private String name; private double weight; private static int numDogs = 0; public Dog(String name, double weight)
Given the below class:
public class Dog {
private String name;
private double weight;
private static int numDogs = 0;
public Dog(String name, double weight) {
this.name = name;
this.weight = weight;
numDogs++;
}
public String getName() {
return name;
}
public double getWeight() {
return weight;
}
public static int getNumDogs() {
return numDogs;
}
public static void increaseNumDogs() {
numDogs++;
}
public void printGreeting() {
System.out.println("Woof!");
}
@Override public String toString() {
return "Name: " + name + " Weight: " + weight;
}
}
1. Add a method call to getNumDogs to the below starter code:
public class DogTest {
public static void main(String[] args) {
Dog fluffy = new Dog("Fluffy", 10);
int num = //call getNumDogs method here!
}
}
1. Dog.getNumDogs();
2. Then, add a method call to the increaseNumDogs method.
3. Lastly, call the printGreeting method. What is different about the way you call this method compared to the prior two methods.
(answer only questions 2 and 3 )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started