0

I started working on Android applications and I find little difficult to understand this piece of code:

LineNumberReader(new FileReader("/proc/tty/drivers"));   

How can I know that the LineNumberReader function accepts FileReader as a new instance of the class? I went through the Java documentation for the LineNumberReader API, it doesn't mention anything regarding FileReader class. There is problem in Java API interpretation which I have to consider, Can any one of you please help me in understanding how an API should be used in Java?

1 Answer 1

4

I suspect you actually saw:

new LineNumberReader(new FileReader("..."))

The LineNumberReader documentation shows a constructor taking a Reader parameter, and FileReader extends Reader. So think of it like this:

Reader reader = new FileReader("/proc/tty/drivers");
LineNumberReader lineNumberReader = new LineNumberReader(reader);

Is that clearer for you?

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Jon, I am clear now . I had one more doubt, in Java documentation link for Reader class it mentions **Known Direct Subclasses ** and **Known Indirect Subclasses **, I am not sure what is the difference between both ? Can we use both classes as you refereed earlier to Reader or it is just known Indirect Subclasses comes under this category?
@RajeshSO: The difference is that direct subclasses will be ones which extend Reader directly whereas indirect subclasses will be ones which extend some other subclass of Reader. Both can be used as Readers. I would strongly recommend that you read an introductory Java book at this point, to clarify inheritance further.
Thanks, Yes I am in process of learning Java. Can you suggest any good book to start with Java? I found Thinking Java makes sense for beginners, do you have any suggestions?
@RajeshSO: I'm afraid I haven't looked at the set of available beginner books in Java for years - I don't really have any useful advice.
No issues, Thanks for everything :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.