how do I Write a line of code to declare and construct a Date object named curDate.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreamer1963
    New Member
    • Mar 2008
    • 6

    how do I Write a line of code to declare and construct a Date object named curDate.

    Write a line of code to declare and construct a Date object named curDate.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    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

    Working...