• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding Doubt

 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot override non-static methods with static methods.

All the Wrapper classes extends the Number class, which in turn extends the Object class.
In the Object Class, toString() is non-static, but in the Wrapper Classes, toString() is static. How does that work?
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhi vijay wrote:

In the Object Class, toString() is non-static, but in the Wrapper Classes, toString() is static. How does that work?


Which Wrapper classes are you talking about? Integer,Double.... ? If so you will have to refer to API for details of those. Because they do have toString() method overriden, plus static toString() (toString(double d) for Double etc...).
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Delete me please]
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the static toString method in the wrapper classes takes a primitive parameter while the non-static toString method of Object class doesn't take any paremeter...
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes! :-(
Sorry for asking such a stupid question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic