Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding

 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I just wanted to know what is wrong in the above code ?
 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is throwing this error : Exception in thread "main" java.lang.Error: Unresolved compilation problem
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An error like "unresolved compilation problem" probably means that you have some old *.class files somewhere and that the compiler gets confused. Delete all your *.class files and re-compile everything again.

What is wrong: Look at lines 2 and 5. What do you think could be wrong there?
 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think overriding of same functions is not possible in same class....am i correct??
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Overriding can only be done by subclasses.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing overloading not overriding.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64985
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mallikarjun don wrote:You are doing overloading not overriding.

He is doing neither.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two doit() methods - the same name, the same arguments. When you call doit() (without arguments) on an A object, how is Java supposed to know which of the two to call?
 
Yunnan Zhou
Ranch Hand
Posts: 31
C++ Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh,my god.you define tow same methos in the same class.
if you want override a method.you first have to inherit another class.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49457
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Yunnan Zhou
Ranch Hand
Posts: 31
C++ Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Campbell Ritchie
thank you so much. nice to meet you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49457
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic