Objects and Collections

Q1:
/* Missing Statement ? */
public class foo 
{
    public static void main(String[]args)throws Exception 
    {
        java.io.PrintWriter out = new java.io.PrintWriter(); 
        new java.io.OutputStreamWriter(System.out,true); 
        out.println('Hello'); 
    } 
}
What line of code should replace the missing statement to make this program compile?

A No statement required.

B import java.io.*;

C include java.io.*;

D import java.io.PrintWriter;

ANS:A - No statement required.

The usual method for using/importing the java packages/classes is by using an import statement at the top of your code. However it is possible to explicitly import the specific class that you want to use as you use it which is shown in the code above. The disadvantage of this however is that every time you create a new object you will have to use the class path in the case 'java.io' then the class name in the long run leading to a lot more typing.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.