1

Q. The following is my code, but I don't understand the output. I thought the output should be 11 3 3.14159 11 8 3.14159 but the output is totally different from what I expected.

public class Time {

    private int hour; 
    private int minute; 
    private double second; 

    public Time () { 
        this. hour = 0; 
        this.minute = 0;
        this.second = 0;
    }
    public Time ( int hour, int minute, double second ) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

public static void main(String[] args) {

  // one way to create and initialize a Time object
  Time t1 = new Time ();
  t1. hour = 11; 
  t1. minute = 3; 
  t1. second= 3.14159; 
  System.out.println(t1);

  // another way to do the same thing
  Time t2 = new Time ( 11, 8, 3.14159); 
  System.out.println (t2);
}

}

**The actual output : Time@7852e922 Time@4e25154f

Rebecca L
  • 65
  • 7

0 Answers0