• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

access specifier

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a class access specfier is default i.e if the class is visible only in the package, then why are the members allowed to have public as access specifier, any way the class will not be available in other packages.so,the members even though public will be visible only in that package
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the class is not visible, then none of its members are visible.
But we have the member methods to be public because mostly all the classes implement interfaces and we are forced to have the methods to be public.

Further in future when the class is made visible outside we need not change the API.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good explanation
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to <<The Java Language Specification>> 8.2.1.4, if a class has a public superclass or superinterface, with the help of another public class in the same package that returns an instance of this class, instance of the class might be available at run time to codes outside its package, and its public methods, which implement or override the methods of its public superclass or superinterface, can be invoked through these instances.
 
Get off me! Here, read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic