File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes public and protected access in non static class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "public and protected access in non static class" Watch "public and protected access in non static class" New topic
Author

public and protected access in non static class

Rajesh k Jha
Ranch Hand

Joined: May 10, 2009
Posts: 72
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

Joined: Jul 23, 2009
Posts: 45

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


Regards
Balraj Kumar
SCJP 5 95%
SCWCD 82%
Preparing for SCBCD
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

public and default access modifiers are the only modifiers that can be used for the top level classes.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public and protected access in non static class
 
Similar Threads
sereral doubs... pls clear them all
Constructor
Question about Inheritance and Static Instance Variable
Overloading or Overriding ?
regarding protected scope