• Post Reply Bookmark Topic Watch Topic
  • New Topic

boolean equals()  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If equals is a public method of Object, and every class inherits from Object, why does this compile in a class:

boolean equals(){return true}
without the public access modifier. Is that not against the rules of overriding?

Thank you
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the equals method at Object takes a parameter(Object o). So you don't override it, you overload it.
 
Tamara Lopez
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry that's my fault, I typed it in wrong
I meant
boolean equals(Object o){returns true;}
This way it still doesn't result in a compiler error.
[ April 05, 2006: Message edited by: Tamara Lopez ]
 
Joerg Waldmann
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will result in a compiler error. Try it.
 
Joerg Waldmann
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your second comment you wrote the access modifier public. Then it will compile, too. But with the default access it won't compile.
 
Tamara Lopez
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok ignore me- sorry - i was typing it different than it was thinking it in my head
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!