aspose file tools*
The moose likes Java in General and the fly likes Which is better (Accessing constants defined in interface) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Which is better (Accessing constants defined in interface)" Watch "Which is better (Accessing constants defined in interface)" New topic
Author

Which is better (Accessing constants defined in interface)

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Hi,
I have a interface which only has constants declared in it. Now to access these constants from a class I can have two ways
1) As the constants are public and static I can access them directly in my class as InterfaceName.ConstantVar
2) I can make the class implememt the interface and then I can directly access the constants of the interface in my class as if they were declared in the class itself. ConstantVar
Which is better?
Thanks & Regards,
Deepak


SCJP, SCWCD, SCBCD
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

There is no point in implementing such an interface. The good way to access static fields is to use the ClassName.FieldName format so that some one looking at your code will know that this field is static.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please keep to SCJP topics in this forum. We have other Java forums for discussing these more general issues. Moving to Java In General (Intermediate).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which is better (Accessing constants defined in interface)