wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overriding" Watch "Overriding" New topic
Author

Overriding

archu sweet
Ranch Hand

Joined: Mar 07, 2011
Posts: 66



I just wanted to know what is wrong in the above code ?
archu sweet
Ranch Hand

Joined: Mar 07, 2011
Posts: 66

It is throwing this error : Exception in thread "main" java.lang.Error: Unresolved compilation problem
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
archu sweet
Ranch Hand

Joined: Mar 07, 2011
Posts: 66

i think overriding of same functions is not possible in same class....am i correct??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Yes. Overriding can only be done by subclasses.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 243

You are doing overloading not overriding.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

mallikarjun don wrote:You are doing overloading not overriding.

He is doing neither.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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

Joined: May 04, 2011
Posts: 31

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.


I'am a Chinese.I like Java.Hello.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Welcome to the Ranch
Yunnan Zhou
Ranch Hand

Joined: May 04, 2011
Posts: 31

to Campbell Ritchie
thank you so much. nice to meet you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
You're welcome
 
Don't get me started about those stupid light bulbs.
 
subject: Overriding