• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A minor confusion about constants..

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Milind Chaudhary
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your answer.. it cleared my doubt..
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic