Advertisement
thenewboston

Java Programming Tutorial - 42 - toString

Aug 22nd, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. public class apples {
  2.    public static void main (String[] args){
  3.       potpie potObject = new potpie(4,5,6);
  4.    }
  5. }
  6.  
  7. public class potpie {
  8.    public int month;
  9.    public int day;
  10.    public int year;
  11.    
  12.    public potpie(int m, int d, int y){
  13.       month = m;
  14.       day = d;
  15.       year = y;
  16.      
  17.       System.out.printf("The constructor for this is %s\n", this);
  18.    }
  19.    
  20.    public String toString(){
  21.       return String.format("%d/%d/%d", month, day, year);
  22.    }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement