Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a SimpleDateFormat Object

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I understand. Where is this variable instantiated ? Are you asking if static can be used inside a method body ?

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic