Question: Define a public class named Dog with a public class variable called count. count should record the total number of instances of the Dog class
Define a public class named Dog with a public class variable called count. count should record the total number of instances of the Dog class that have been created. Provide a Dog constructor that take a single String argumentthe name of the Dog being created. Assuming your static variable works properly: System.out.println(Dog.count); // prints 0 Dog chuchu = new Dog("chuchu"); System.out.println(Dog.count); // prints 1 Dog lulu = new Dog("Lulu"); Dog sheldon = new Dog("Sheldon"); System.out.println(Dog.count); // prints 3
in Java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
