Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i class be named Object?

 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi !!
can a class be named Object ??
like:
class Object {
public static void main(String args[]) {
System.out.println("hello");
}
}
and be saved as Object.java?
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are that original of a thinker try it. i want to. I would have to say no though because(if nothing else) your class is in the default package and so is java.lang.* which includes java.lang.Object
 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried it and it is working fine like any other class .
then what is the difference between java.lang.Object and this user defined one ?
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is the package name. You class isn't in the java.lang package. Your class will still extend java.lang.Object though because ultimately every class has to! I think it owuld be very confussing to have another class called Object though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic