• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the significance of a non-public class?  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We know that classes can either be public or default/no modifier. I was wondering what is the significance of a non-public class or a default class?

Can anyone provide me with a practical example to illustrate how a default class is useful in real life?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the class can't be used outside of the package. It's useful for classes that only have a meaning for internal structures.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine an automobile. An automobile is made up of hundreds if not thousands of parts. The parts are, in general, organized into systems -- the drive train, the ignition system, the fuel system, the electrical system. Within each system, there are a few parts that bridge between systems: for example, the spark plugs serve as a sort of connection between the electrical system and the drive train. The tires serve as a sort of connection between the drive train and the road. The steering wheel is the interface between the steering system and the driver. But there are hundreds of parts (Cotter pins, axles, struts, piston rings, bolts) which are internal to a system and are normally never exposed.

In the analogous Java program, a system becomes a package; the few special parts are the public classes; and the vast majority of behind-the-scenes parts are the non-public classes.
 
Anchit Herredia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!