document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  /**
  2.  * this used implicitly and explicitly to refer to members of an object.
  3.  *
  4.  * @author Migel Aulia Mandiri Putra
  5.  * @version 0.1
  6.  */
  7.  
  8. public class ThisTest
  9. {
  10.     public static void main (String[] args)
  11.     {
  12.         SimpleTime time = new SimpleTime(15, 30, 19);
  13.         System.out.println(time.buildString());
  14.     }
  15. }
  16. // class SimpleTime demonstrates the "this" reference
  17. class SimpleTime
  18. {
  19.     private int hour;
  20.     private int minute;
  21.     private int second;
  22.    
  23.     public SimpleTime(int hour, int minute, int second)
  24.     {
  25.         this.hour=hour;
  26.         this.minute=minute;
  27.         this.second=second;
  28.     }
  29.  
  30.     // use explicit and implicit "this" to call toUniversalString
  31.     public String buildString()
  32.     {
  33.         return String.format( "%24s: %s\\n%24s: %s",
  34.             "this.toUniversalString()", this.toUniversalString(),
  35.             "to UniversalString()", toUniversalString() );
  36.     }
  37.  
  38.     // convert to String in universal-time format (HH:MM:SS)
  39.     public String toUniversalString()
  40.     {
  41.         return String.format( "%02d:%02d:%02d",
  42.             this.hour, this.minute, this.second );
  43.     }
  44. }
');