aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes BufferedReader 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 "BufferedReader " Watch "BufferedReader " New topic
Author

BufferedReader

wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23


Hi all,
I have a problem with line 1.
Not sure what is problem..
I thought since BufferedReader is subclass of Reader , the assignment would be ok.
Can anyone explain? Thanks!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
No compilation errors for me. What's your problem?
Maybe you are getting an IOException?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Vivian Josh
Ranch Hand

Joined: Oct 31, 2006
Posts: 112
Hi,

This code compiles fine. You should elaborate more on your type of error. May be you have not imported all the needed API classes.

HTH,

Vivian
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
There aren't any compilation error noe any IOException while running the code!! What exactly the complilation error/excepion you are getting??


"History would be kind to me, for I intend to write it."
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383


If you change your code as above you wont find any problem. Because Reader class is abstract, you cannot instantiate it.


SCJP-1.5<br />SCWCD-1.4
wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23
Hmm..
I'm having a compilation error as follow.Thanks for the quick reply.

Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
Well Dolly we aren't instantiating Reader Interface here..we are just assiging the reference of the BufferedReader object to Reader refernce varialble and since BufferedReader implements Reader hence BufferedReader "IS A" Reader..

the code is absolutely fine..sheena I hope you are using javac 1.5 compiler..because that is the only reason I can think of for not compliling the code !!!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

Do you have a class named 'Reader' (that you wrote yourself) in the same directory as the TestIO class?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23
Do you have a class named 'Reader' (that you wrote yourself) in the same directory as the TestIO class?

There is a class named Reader i wrote myself..After I deleted it, the same error still occur.
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Make sure you deleted .class file too.


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23
Hi all.. The problem it is due to a public class named Reader I wrote myself inside..So i renamed the file from Reader.java to Reader(renamed).java and deleted the Reader.class file..

The compilation succeeded.Thanks all!
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Bye the way Priyam Reader is not an Interface. It is a class.

Wong, Though the code raise error(Incompatible types) But it compiles & runs fine.
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
ok mistake accepted it's a class..but still superclass refrence variable can refer to a sub-class object..Polymorphism !!!
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
yeah, you are right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BufferedReader