#单例对象
The object's constructor is called when the object is first used
#伴生对象
When a singleton object has the same name as a class, it becomes the associated object
Class helloworld{...}
Object hellworld{...}
Classes and associated objects can access private properties, but must exist in the same source file
The associated object of the class can be accessed, but not in scope
Apply method: not carefully spoken
Practice:
Write a time class that joins the private properties hours and minutes
Add method Get, query hours,minutes value, and output (hours,minutes)
Adding method Do,min 1, if min=60 time is 0, and hour increases 1, if hours=24, when, 0
The time object is constructed as new Time (H,min), h,min is int, and 0<=h<23, 0<=min<59
Class time{
private Var hours=0
private Var minutes=0
def get () {println (hours,minutes)}
Def get_h () {println (Hours)}
Def get_min () {println (minutes)}
Def do1 () {
Minutes +=10
if (minutes==60) {
Minutes=0
Hours+=1
if (hours==24) {
Hours=0
}
}
}
}
Object-Oriented: Object