This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader

 
wong sheena
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No compilation errors for me. What's your problem?
Maybe you are getting an IOException?
 
Vivian Josh
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There aren't any compilation error noe any IOException while running the code!! What exactly the complilation error/excepion you are getting??
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you change your code as above you wont find any problem. Because Reader class is abstract, you cannot instantiate it.
 
wong sheena
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm..
I'm having a compilation error as follow.Thanks for the quick reply.

 
Priyam Srivastava
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a class named 'Reader' (that you wrote yourself) in the same directory as the TestIO class?
 
wong sheena
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you deleted .class file too.
 
wong sheena
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok mistake accepted it's a class..but still superclass refrence variable can refer to a sub-class object..Polymorphism !!!
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, you are right
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic