• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding  RSS feed

 
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
 
Java Cowboy
Sheriff
Posts: 16083
88
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??
 
Sheriff
Posts: 21330
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Overriding can only be done by subclasses.
 
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing overloading not overriding.
 
Author and ninkuma
Marshal
Posts: 66690
167
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
Sheriff
Posts: 16083
88
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?
 
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.
 
Marshal
Posts: 59146
180
  • 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
Marshal
Posts: 59146
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!