troubleshooting Question

Java Class Constructor Parameters with range limits

Avatar of thomaszhwang
thomaszhwangFlag for United States of America asked on
4 Comments1 Solution447 ViewsLast Modified:
I'm new to Java and I'm asking this question just to help me better understand OOP.

Let's say I'm defining a new Class called Hour. To instantiate this Class, we need to specify an integer to indicate the hour of this instance.

Hour hr = new Hour(16); // this means to define an hour that indicates 4pm.

So when we define the Hour Class here, the parameter for the constructor should within the range [0, 24). How can we define such a parameter and can I throw an error when a parameter that is out of this range is specified?

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros