This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Creating a SimpleDateFormat Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating a SimpleDateFormat Object" Watch "Creating a SimpleDateFormat Object" New topic
Author

Creating a SimpleDateFormat Object

ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

Hi all ,


I read a piece of code as follows

static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");

We cannot have modifiers attached to the constructors , then how are we assigning a non static object to a static reference ?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

I am not sure I understand. Where is this variable instantiated ? Are you asking if static can be used inside a method body ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Ragi, a reference variable (whether its static or not) can refer to an object (objects are always non-static).
This is just a reference variable declared inside a class which is static, it has nothing to do with constructors declared as static. Since this reference variable is static, all the objects of the class in which its declared will share the same reference variable...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
jQuery in Action, 2nd edition
 
subject: Creating a SimpleDateFormat Object
 
Similar Threads
SimpleDateFormat
How to get tomorrow's date?
Format method in SimlpleDateFormat
How to fetch Date from DateTime in mySql
Date Format Problem And Hashtable ......