• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Class duplication

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I created a class named fun in java.lang package.The code snippet are as
follows:
class Object
{
public void show()
{
System.out.println("fun");
}
}
public class fun {
public static void main(String [] a)
{
new Object.show();
}
}

JVM executed the my Object class's show method.
My query is:
Why did the JVM allowed me to create a my own Object class
when there is already an Object class in the java.lang package.


 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this thread to the beginner section...
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<CODE>Object</CODE> is not a reserved keyword so you can reuse it - at your own risk
In your class, because you hid the Object class name, you can still refer to it using
<CODE>java.lang.Object</CODE>
Any appearance of simply <CODE>Object</CODE> will be a reference to your class.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic