Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public and protected access in non static class

 
Rajesh k Jha
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use more than one public class in a java file,if yes then in 1 and 2 why i am getting error "The public type must be defined in its own file"

also in line "public class suTest extends Test9" we can't try protected as non-nested class can have only public and default access level but why when i try to use public it shows error?

Things has really got mess up? Please clarify

 
Balraj Momi
Ranch Hand
Posts: 45
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use more than one public class in a java file


Answer to this question is No. We can not have more than one public classes inside one source file. And also your source file name should match exactly with public class inside your file. On other side you can have any number of default access classes inside same source file.

we can't try protected as non-nested class

protected is not allowed as access modifier for non inner classes, only public and default are allowed.

Regards Balraj
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public and default access modifiers are the only modifiers that can be used for the top level classes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic