It's not a secret anymore!
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Creating a SimpleDateFormat Object" Watch "Creating a SimpleDateFormat Object" New topic

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

Joined: Feb 24, 2006
Posts: 6662

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

Joined: Aug 03, 2008
Posts: 9463

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
I agree. Here's the link:
subject: Creating a SimpleDateFormat Object
It's not a secret anymore!