Question: Class Counter { private in count; public Counter(int intialCount){ count = initialCount; } public Count(){ count = 0; } public void increment(){ count += 1;
Class Counter {
private in count;
public Counter(int intialCount){
count = initialCount;
}
public Count(){
count = 0;
}
public void increment(){
count += 1;
}
public void reset(){
count = 0;
}
public int getValue(){
return count;
}
}
1. How many constructors does this class have?
2. How many methods does this class have?
3. Write a declaration that declares a Counter variable named ctr and initializes it to contain a Counter object that contains the number 0.
4. Write a statement that increments the value stored in the ctr object.
5. Write a statement that changes the values stored in the ctr object to zero.
6. Write a statement that prints the values stored in the ctr object.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
