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 class name ? 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 "class name ?" Watch "class name ?" New topic
Author

class name ?

Ambapali Pal
Ranch Hand

Joined: Dec 17, 2002
Posts: 47
I have 2 questions regarding this.
1. Can a class have same name as the package included in the package statement ?
2. Can any kind of nested or inner class wheather inside or outside method have same name as the nesting class ?
Thanks in advance.
Ambapali
Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
Hi,
I'm sure that inner classes cannot have the same name as the enclosing class.


SCJP 1.4
praveena kuppachi
Greenhorn

Joined: Jan 24, 2003
Posts: 15
I think a class can have a same name as that of its package,but it may lack readability.
lets say theres a class called blah1 placed in a package called blah1.then any class using the contents of blah1 looks like this:
import blah1.blah1;
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
In general, the best way to answer that quickly is to write a piece of code (of course only if you have a compiler at hand
Here we go:
1. Can a class have same name as the package included in the package statement ?
The following code compiles fine

2. Can any kind of nested or inner class wheather inside or outside method have same name as the nesting class ?
Neither of the following inner/nested classes are legal.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Ambapali Pal
Ranch Hand

Joined: Dec 17, 2002
Posts: 47
Yeah I tried both of them . 1st one compiles fine and 2nd one does not. I was confused by the Sybex Java Certification 1.2 book, which says that a class cannot have same name as the package. I did not check their errata yet.
Thank you ,
Ambapali
 
wood burning stoves
 
subject: class name ?
 
Similar Threads
instanceof always returns false
Confusion
What are NameSpaces
package name and class name
How To access a class that has same name as an inner class ?