Object-Oriented: Object

Source: Internet
Author: User

#单例对象

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.