• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance or something else?  RSS feed

 
Rod Taylor
Greenhorn
Posts: 25
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I encountered this line of code:



Now, my question is: how is it possible that it's using FileReader class as an argument to the constructor? According to Java 7 API, the constructor for BufferedReader class is BufferedReader(Reader in), i.e. my understanding is that it should have an object of type Reader or Reader's subclasses, and FileReader is not even a subclass of Reader. How is this possible?

Thank you.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileReader is a subclass of InputStreamReader which is a subclass of Reader.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Click on one of the FileReader links in these posts, and at the top of the Javadoc page you can see the complete inheritance hierarchy.
 
Rod Taylor
Greenhorn
Posts: 25
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:FileReader is a subclass of InputStreamReader which is a subclass of Reader.


I see now that it doesn't need to be a direct subclass, i.e. a FileReader "is" a Reader by indirect inheritance.


Matthew Brown wrote:Click on one of the FileReader links in these posts, and at the top of the Javadoc page you can see the complete inheritance hierarchy.


Somehow I missed this!?? Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!