Which of the following lines can be inserted at line 1 to make the program run? //line 1
public class TestClass{
public static void main(String[] args){
PrintWriter pw = new PrintWriter(System.out);
OutputStreamWriter osw = new OutputStreamWriter( System.out );
pw.print("hello");
}
}
Assume that PrintWriter and OutputStreamWriter are valid classes in java.io package.
Enthuware answer say option 3 is correct answer, but when i put this code, it needs both option 2 & 3 to compile this code without error. (import java.io.*; and also import java.io.OutputStreamWriter;)
I was given following options
1) import java.lang.*;
2) import java.io.*;
3) import java.io.OutputStreamWriter;
4) include java.io.*;
5) include java.lang.System;
About Question enthuware.ocajp.i.v7.2.1232 :
Moderator: admin
-
- Posts: 5
- Joined: Sun May 21, 2017 9:01 pm
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1232 :
I see that option 2 i.e. import java.io.* is marked as the correct option. If you have already imported java.io.*; you shouldn't need to import java.io.OutputStreamWriter; because OutputStreamWriter is a member of java.io package.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Sun May 21, 2017 9:01 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1232 :
Thanks for your response. Does that mean answer from the test is wrong ? As you mentioned, even i select import java.io.*;
Probably you need to update the question bank.
Thanks
Shri
Probably you need to update the question bank.
Thanks
Shri
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1232 :
No, what I mean to say is that the correct option set in the question bank for this question is option 2. Option 3 is not set as the correct answer. In other words, the question bank is correct.
See attached image. If this is not what you see, please post the screen shot of what you see.
See attached image. If this is not what you see, please post the screen shot of what you see.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 61 guests