Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Wednesday

JAVA PROGRAMMING TUTORIAL 31: THIS

// "this" is a reference to current object whose method or constructor is being called.

public class HackDefence{

public static void main(String[]args){

HackDefence toStringObject = new HackDefence(8,5,6);

}

private int hour;

private int minute;

private int second;

public HackDefence(int h, int m, int s){

hour = h;

minute = m;
 
  second = s;

            System.out.printf("The constructor for this is %s\n ", this);

}

public String toString(){

return String.format("%d:%d:%d",hour,minute,second);

}

}

OUTPUT:

1 comment:

Related Posts Plugin for WordPress, Blogger...