aspose file tools*
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 Spring in Action this week in the Spring 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: 6662
    
    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: 9305
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a SimpleDateFormat Object