Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Private Accessibility

 
Phillipe Rodrigues
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request more explanation on the "Private" accessibility modifier with reference to below example:Why I should get the below error?






Output:

---------- Compile ----------
Sub_class.java:1: modifier private not allowed here
private class Sub_class extends Super_class

1 error

Output completed (1 sec consumed) - Normal Termination
 
Shiva Kumar Shedad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all a class cannot be made as private whether it extends another class or not...
Because it doesnot make sense...

Originally posted by Phillipe Rodrigues:
Request more explanation on the "Private" accessibility modifier with reference to below example:Why I should get the below error?






Output:

---------- Compile ----------
Sub_class.java:1: modifier private not allowed here
private class Sub_class extends Super_class

1 error

Output completed (1 sec consumed) - Normal Termination
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classes can actually be private, but I have only seen that inside other classes. If a class isn't inside another class, private access would mean it would be inaccessible to any code from anywhere.
 
Shiva Kumar Shedad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Classes can actually be private, but I have only seen that inside other classes. If a class isn't inside another class, private access would mean it would be inaccessible to any code from anywhere.


Thanks Ritchie. I had forgotten about the inner classes while replying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic