• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class declaration

 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A file can have more that one nonpublic class.Can we declare a class as protected or private.If not why..?
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Topmost classes (non-inner) can have only public access modifier or non.
Why? Private class wouldn't be accessible by non other. And protected access is quite the same, except subclasses could access it, but what's the use when they can't be accessed by any other class?
[ May 26, 2008: Message edited by: Ivan Ivanic ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have protected and private classes, yes, but I think only nested or inner classes.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sarath Koiloth Ramath:
A file can have more that one nonpublic class.Can we declare a class as protected or private.If not why..?


An inner class can be private or protected. I have however found no use for them in the real world.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic