The role of this Java learning note

Source: Internet
Author: User

?

The invocation of a variable in a class should actually be: the object name. Variable Name

1.this represents the object that called the member, usually omitting the object name, which omits this. However, the variable with the same name cannot be omitted when it participates. As in the following scenario:

Public void setnum(String num)
{
This . num = num;
}

?

2. When another constructor is called in one of the constructors in the same class, you can use this to call directly. However, when used, the sentence containing this must be placed in the first line of the code block. As in the following scenario:

public Time(long totaltime)//以特定时间(ms)构造time对象的构造方法

{

this(totaltime / 1000, totaltime / 60000, totaltime / 3600000);//调用以特定时,分,秒为参数的构造方法,传入转化后的流失时间

}

?

public Time(long totalsecond, long totalminute, long totalhour)

{

/*将已流失的时间转化为当前的时间*/

currsecond = totalsecond % 60;

currminute = totalminute % 60;

currhour = totalhour % 24;

}

The purpose of this Java learning Note

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.