• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class name ?

 
Ambapali Pal
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm sure that inner classes cannot have the same name as the enclosing class.
 
praveena kuppachi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ambapali Pal
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic