Author Topic:   two from Hunt's
Indy
greenhorn
posted April 25, 2000 12:29 PM             
These two questions are all from John Hunt.

47. Which of the following illustate how an InputStreamReader can be created.

A. new InputStreamReader(new FileInputStream("data"));
b. new InputStreamReader(new FileReader("data"));
C. new InputStreamReader(new BufferedReader("data"));
D. new InputStreamReader("data");
E. new InputStreamReader(System.in);

the answer is A.&E. I selected B instead of A. High-level reader receives args of low-level reader--that's what I am thinking about this. Please correct me. And, how much are we supposed to know about I/O for exam? I have a anonymous test including several questions about files, dircetory, which are driving me crazy.

63.
public class Test5{ public static void main (String args[]){
if (true) {
Test5=new test4();
System.out.println("Done the test");
}
System.out.println("The end");
}
}

In the answer, "the program prints out "The end" and nothing else. I can't figure out why "Done the test" isn't printed out.

Tony Alicea
sheriff
posted April 25, 2000 07:10 PM             
47. Which of the following illustate how an InputStreamReader can be created.
A. new InputStreamReader(new FileInputStream("data"));
b. new InputStreamReader(new FileReader("data"));
C. new InputStreamReader(new BufferedReader("data"));
D. new InputStreamReader("data");
E. new InputStreamReader(System.in);

the answer is A.&E. I selected B"

The question is essentially what can make a Reader out of a Stream.

A is True. Almost self-explanatory.

B is already a Reader

C Not a valid constructor for BR.

D invalid argument

E Yes because Systen.in is an InputStream (check the API).

maha anna
bartender
posted April 26, 2000 12:13 AM             
Indy,
For your first qstn, InputStreamReader class is just designed for reading from an InputStream rather than a reader . It takes only InputStream as an argument for its constructor. So the answer b) which takes a FileReader as arg to its constructor will not compile at all. This is the Reader class which reads from a low level InputStream. And simillarly 'OutputStreamWriter' also behaves like this. It writes to a OutputStream rather than a Writer.

So the 2nd ans is invalid.

Regarding the qstn 63) I see the something slightly different from what u posted here.
The qstn is foll. And the answer given is also correct. Because, it tests how comments are used in Java program. When you start a comment with /* , the comment ends only when */ is reached. So in this program all other code after /* and before */ are considered as part of comment and the program just prints 'The end'.



public class Test5 { public static void main (String args []) {
/* This is the start of a comment
if (true) {
Test5 = new test5();
System.out.println("Done the test");
}

/* This is another comment */
System.out.println ("The end");
}

}


regds
maha anna

[This message has been edited by maha anna (edited April 26, 2000).]

Indy
greenhorn
posted April 26, 2000 09:36 AM             
Thank you very much. How tricky. I need to sharpen my eyes by more practicing.

Indy

|