File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object has the same name as class

 
sumit kar
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens
when the OBJECT HAS THE SAME NAME AS THE CLASS NAME
example:Test Test=new Test();

WHAT R THE VARIOUS PROBLEMS WE WILL FACE
AND HOW DOES THE COMPILER INTERPRET THIS IN DIFFERENT TYPES OF STATIC AND NON-STATIC METHOD CALLS.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THERE IS NO PROBLEM WITH THIS AT ALL. VARIABLE NAMES AND CLASS NAMES ARE IN ALTOGETHER DIFFERENT NAMESPACES AND DON'T INTERFERE WITH EACH OTHER AT ALL, IN ANY CONTEXT. YOU CAN ALSO HAVE A METHOD WHOSE NAME IS THE SAME AS THE CLASS IT APPEARS IN, SO, FOR EXAMPLE, THE FOLLOWING CODE WOULD BE PERFECTLY LEGAL JAVA:

TEST TEST = new TEST().TEST();

P.S. ARE YOU FROM NIGERIA?

P.P.S. I'M MOVING THIS TO JAVA IN GENERAL (BEGINNER).
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My eyes are ringing from all the shouting.
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to note that objects don't have names. It is this very fact that makes it extremely difficult to talk about objects, and results in great confusion. What you have there is an "object reference", which do have names; the object referred to by the reference does not.

This might help: http://qa.jtiger.org/GetQAndA.action?qids=75&showAnswers=true&showCodeLineNumbers=true
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As literal and precise as the distinction may be, I don't find it very helpful to insist on saying 'the object (in memory) referred to by "o"' any more than it's helpful to say 'the object (on the floor) referred to by "chair"'.
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ernest:
As literal and precise as the distinction may be, I don't find it very helpful to insist on saying 'the object (in memory) referred to by "o"' any more than it's helpful to say 'the object (on the floor) referred to by "chair"'.


I teach at a university; I see this often:
"my object cannot be null, why do I get NullPointerException?"
"Object x; when is x eligible for garbage collection?"
"Java passes primitive types by value, and objects by reference"
"...but I created the array with 'new', yet the elements are still null"
<insert-a-zillion-other-remarks-here/>

Can you see the problem by not providing the distinction?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ernest:
As literal and precise as the distinction may be, I don't find it very helpful to insist on saying 'the object (in memory) referred to by "o"' any more than it's helpful to say 'the object (on the floor) referred to by "chair"'.


In a discussion between experienced developers, I'd probably agree.

In a beginner's forum, I'd assume that it helps to be more pedantic, because differentiating between an object and reference variables is a common problem for beginners.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic