*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes two calss in one singel .java file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "two calss in one singel .java file?" Watch "two calss in one singel .java file?" New topic
Author

two calss in one singel .java file?

james gong
Ranch Hand

Joined: May 29, 2001
Posts: 48
if there are two class in a .java file ,one class is declared public why the other can't
declared protected or private (the compiler complain that :there is no declaration)
Nitin Mishra
Greenhorn

Joined: Jul 09, 2001
Posts: 3
u can use modiefiers with inner classes only


Nitin Mishra
james gong
Ranch Hand

Joined: May 29, 2001
Posts: 48
can you give the clearly concept of a modifier,and whethe it includes access modifier(public private,protected,default)?
Snylt Master
Ranch Hand

Joined: Jul 07, 2001
Posts: 55
I agree with Nitin
Access modifers are private , protected , public and default.
You don't type default only class test{}.
A class can only be marked as public or default. Methods can be marked with private , protected , public and default. Inner classes can be marked private , public , default. I don't know if an innerclass can be marked protected. By i think you can. Anyone who can fill me in.
// Snylt Master


Preparing for the Java 2 Certification exam
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3253
    
    2
>if there are two class in a .java file ,one class is declared public why the other can't
Well, as Java is sometimes called C++ --, this is one of the rules meant to increase maintainability, productivity and reduce confusion, error prone constructs etc.
Suppose you have two public classes in one java file. Now you quit the job and someone else tries to run one of the public classes whose name does not match the name of the java file and finds that there is a bug. He/She will surely have a trouble finding what file this class is defined in.
Yes, this can also happen with non-public classes defined in one file and although it is not prohibited but it is definitly discouraged unless all the classes in that file are strongly related.
HTH,
Paul.

------------------
SCJP2 Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
www.enthuware.com/jqplus

Your guide to SCJD exam!
www.enthuware.com/jdevplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: two calss in one singel .java file?
 
Similar Threads
Can u we have global variables in Java!
doubt about public??
Javacodes in JavaScript
Doubt in overridiing
Java 1.5 test Exercise 5-4 Sun Certified Programmer for Java 5