011-002-010
Default Constructor
Medium
Problem Description
Default constructor
In this problem, you will explicitly define a no-argument default constructor in the Counter class, initialize the count field to 0, read an integer n from standard input, call increment() n times, then print the initial and final values.
Learning Objective: Understand the role of default constructor and explicit definition
Overview
Explicitly define a no-argument default constructor and set default values.
Specifications
- Define no-argument constructor in Counter class
- Initialize count field to 0
- increment() method increases count
- getValue() method returns current value
- Read the number of increments
nfrom standard input
Input Format
n
n: number of increments (non-negative integer)
Output Format
Initial: 0
After n increments: n
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up