Write a line of code to declare and construct a Date object named curDate.
how do I Write a line of code to declare and construct a Date object named curDate.
Collapse
X
-
Tags: None
-
How do you declare an integer?
[CODE=java]int myIntVariable;[/CODE]
If you want this variable to have a value, you would initialize it like so:
[CODE=java]int myIntVariable2 = 5;[/CODE]
Now, an object reference is just like any other variable. So, if the class is named Date, and you want your variable name to be curDate, you say:
[CODE=java]Date curDate;[/CODE]
That takes care of the declaration. The construction is like initializing the integer variable, but the syntax is a little different:
[CODE=java]Date curDate = new Date();[/CODE]
This also has a different name - it is called instantiation, and we call curDate an instance of the Date class.
Comment