This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A minor confusion about constants.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "A minor confusion about constants.." Watch "A minor confusion about constants.." New topic
Author

A minor confusion about constants..

Milind Chaudhary
Greenhorn

Joined: Jul 09, 2010
Posts: 20
When I was reading interfaces, it was in K&B that interface constants are public static final implicitly.
Normal constants are final implicitly and they are not public static...
Just tell me am I correct?

And also answer to the fact that why a class cannot be declared protected?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Milind Chaudhary wrote:When I was reading interfaces, it was in K&B that interface constants are public static final implicitly.
Normal constants are final implicitly and they are not public static...
Just tell me am I correct?

constant are final variables, If you defined your own final variable, you should defined it with final key word. For interface, whether you defined the variable with or without any of the modifier(public, static, final), those variables are implicitly public static final. For others, you should defined with the keyword final.
Milind Chaudhary wrote:
And also answer to the fact that why a class cannot be declared protected?

What's the purpose of making a class protected?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Milind Chaudhary
Greenhorn

Joined: Jul 09, 2010
Posts: 20
Thanks for your answer, but I want to know what is a class's visibility when it is protected and what's the harm in making it protected..How does a protected class behave? Please elaborate.. though this is only for my knowledge and not for exam..
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

protected member of class A can be accessed from class B[which is the subclass of A] even if B is in different package. here notice a point *class A must be public to visible in other packages*. so it doesn't make a sense to declare class as protected

hth
Milind Chaudhary
Greenhorn

Joined: Jul 09, 2010
Posts: 20
Thanks a lot for your answer.. it cleared my doubt..
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: A minor confusion about constants..
 
Similar Threads
Workaround no "static abstract" methods?
A Query about static variables
Question from JQ+ mock exam
Interface
Fields of interface - are they public?