File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloaded vs Overriden Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloaded vs Overriden" Watch "Overloaded vs Overriden" New topic
Author

Overloaded vs Overriden

Tayitu Betule
Ranch Hand

Joined: Dec 18, 2009
Posts: 39
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

Joined: Apr 10, 2010
Posts: 308
you miss the import statement


Bye,
Nicola
Tayitu Betule
Ranch Hand

Joined: Dec 18, 2009
Posts: 39
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

Joined: Apr 10, 2010
Posts: 308
yout still miss it and...you don't need to import java.lang package

it's

sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

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.


Thanks & Regards
Sumit Kothalikar
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

The code compiles just fine after including the IO package
haha
something wrong with your jdk, try reinstalling it

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloaded vs Overriden