• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access Modifier  RSS feed

 
K Elangovan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My class name is with public as access modifier. I used to give the same name as file name. But i am getting error while i tried to compile. But its working fine when i removed the access modifier.
Is there any rule like this?
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Can u give what error as given during compilation?
And what is the first line of ur class.
i mean the class defination.
thanks,
Chinmay
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have more than one class in the file?
If you have a public class in a file it must match the name of the file (icluding case).
You can not have more than ONE public class in a file. You can have many non-public classes in the same file.
If you only have one class in a file it does not have to be public.
 
K Elangovan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cindy & Chinmay,
I worked for Cindy's concepts and now the coding works fine.
Cheers ,
Elangovan.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!