This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloaded vs Overriden

 
Tayitu Betule
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code taken from K&B. The book says it should compile fine, when I tested it... it gave me a compiler error. Why?



Thanks a lot.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you miss the import statement
 
Tayitu Betule
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I have it in the code... just forgot to paste it here. This is what I have.

import java.lang.*;

public class Foo {
public void doStuff(int y, String s) { }
public void moreThings(int x) { }
}

class Bar extends Foo {
public void doStuff(int y, long s) throws IOException { }
}

My question is doStuff is an overloaded method... it should not give a compiler error it throws exceptions.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yout still miss it and...you don't need to import java.lang package

it's

 
sumit kothalikar
Ranch Hand
Posts: 91
Notepad
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;

Really you must include the above package to compile .
And if you have already included in your code then let me make you sure that is overloaded method.
the code compiles good after importing quoted package.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code compiles just fine after including the IO package
haha
something wrong with your jdk, try reinstalling it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic