• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Specifier of class: Guidelines to share..

 
Nitin Bhagwat
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Java. Some rules / guidelines i found for access specifiers for classes are as under: (Please let me know if any other you know!)

Access Specifier of class:
==========================
All these rules also applicable to subclasses.

1.public class rule:
In one Java file, there can be maximum one public class. This class must be name of that java file.
For example, in java file samplepgm.java , public class can be only "public class samplepgm{//code }"

2.private or protected class rule:
A class can be defined as private or protected only if it is inner class within another class (not a inner class defined in a method).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request that display names follow the patter FIRST_NAME + SPACE + LAST_NAME. Your previous display name of "Nitin Bhagwat" was fine.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u r almost there ....just to extend to that ..... in ur 1) rule ...where u r telling about public classes ... the main method has to b there, in that class ... and hey we r missing the "default" modifier ... that means scope within the package ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic