• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class name ?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm sure that inner classes cannot have the same name as the enclosing class.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic