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
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;
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.
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