Answer:
The code to this question can be given as:
code:
public class Exercise09_04Extra //define class
{
public static void main(String[] args) //define main method
{
SimpleTime time = new SimpleTime(2,3,4);
//create object of the class
System.out.println("Hour: " + time.hour + " Minute: " + time.minute + " Second: " +time.second); //print result
}
}
class SimpleTime //define class
{
int hour,minute,second; //set three integer variable
SimpleTime( int hour, int minute, int second ) //define parameterized constructor
{
this.hour = hour;
this.minute = minute;
this.second = second;
}
}
Output:
Hour: 2 Minute: 3 Second: 4
Explanation:
In the above java code firstly we define a main class that is Exercise09_04Extra. In this class we create another class object that is SimpleTime . Then we call parameterized constructor and print the values. When we call the SimpleTime class in this class we define an integer variable that is hour, minute and second and create the parameterized constructor and pass the variable as a parameter.In this constructor we use this keyword to hold the value of the passing variable. So the output of the following code is "Hour: 2 Minute: 3 Second: 4 ".