Question:

Which of the following method of Date class constructs Date object using current system time in Java?

Show Hint

The constructor {Date()} initializes a Date object with the current system date and time.
  • Time()
  • Day()
  • Dt()
  • Date()
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understanding the Date class in Java.
The Date class in Java belongs to the java.util package and is used to represent date and time information. It provides constructors and methods to work with dates and system time.
Step 2: Purpose of the Date() constructor.
The constructor Date() creates a Date object that represents the current date and time according to the system clock. When this constructor is used, Java automatically retrieves the current system time.
Example:
Date today = new Date();
This statement creates a Date object containing the current date and time of the system.
Step 3: Evaluation of options.
(A) Time(): Incorrect. This is not a valid constructor of the Date class.
(B) Day(): Incorrect. This method does not create a Date object.
(C) Dt(): Incorrect. This is not a valid Java method.
(D) Date(): Correct. It constructs a Date object using the current system time.
Step 4: Conclusion.
Thus, the constructor used to create a Date object with the current system time is Date().
Final Answer: Date()
Was this answer helpful?
0
0