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 Tricky Class Name..? 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 "Tricky Class Name..?" Watch "Tricky Class Name..?" New topic
Author

Tricky Class Name..?

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
can anyone explain me about this...

test22.java:13: duplicate class: test22.abc
class abc
^
test22.java:25: cannot find symbol
symbol : class abc
location: class test22
test22.abc x=me.new abc();
^
test22.java:25: cannot find symbol
symbol : class abc
location: class test22
test22.abc x=me.new abc();
^
3 errors[CODE]

Thanx


Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
above, you defined

class test22$abc{
public test22$abc()
{
System.out.println("Outer");
}}


Your inner class will have exactly same name, so its a duplicate. test22$abc will be the compiled name of the inner class.
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
HI, thanx for you reply

but could you please elaborate watz going on behind the scenes..

thanx
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
as you already probably know,

the inner class is compiled into its very own class file

its name is Outerclassname plus '$' plus Innerclassname plus '.class'

so in your case, your inner class will be compiled to test22+$+abc+.class

ending up as test22$abc.class

exactly same as your other class

so its a duplicate
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
From the Java Language Specification (JLS) 3rd Edition: "The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems."

The Java compiler generates nested class names containing $, so programmers should definitely avoid using it in class names. Within string literals or as a character to be input, processed, and output, the appearance of '$' is perfectly normal.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tricky Class Name..?