/**
* this used implicitly and explicitly to refer to members of an object.
*
* @author Migel Aulia Mandiri Putra
* @version 0.1
*/
public class ThisTest
{
public static void main (String[] args)
{
SimpleTime time = new SimpleTime(15, 30, 19);
System.out.println(time.buildString());
}
}
// class SimpleTime demonstrates the "this" reference
class SimpleTime
{
private int hour;
private int minute;
private int second;
public SimpleTime(int hour, int minute, int second)
{
this.hour=hour;
this.minute=minute;
this.second=second;
}
// use explicit and implicit "this" to call toUniversalString
public String buildString()
{
return String.format( "%24s: %s\\n%24s: %s",
"this.toUniversalString()", this.toUniversalString(),
"to UniversalString()", toUniversalString() );
}
// convert to String in universal-time format (HH:MM:SS)
public String toUniversalString()
{
return String.format( "%02d:%02d:%02d",
this.hour, this.minute, this.second );
}
}