In Scala if I create a class like this:
class Time(var hour: Int) {
if (hour < 0) hour = 0
}
I can comfortably create a new object using
x = new Time(4)
If I need to get the time for the x
object I can do
x.hour
and I get back res5: Int = 4
which is cool. But considering I want to change the hour
variable of x
is doing x.hour = 5
enough? I think so. Is there another way to do this.
My main question is. How would I create another object, if i didn't want to use the new
keyword?