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
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