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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!