Java MCQ Set-4 : Multiple Choice Questions in Java Set-4

Set-5 Java MCQ

  1. Which of the following statement is true

a. You can directly read text from a FileReader.
b. You can directly write  text to a File Reader.
c. You can directly read ints and floats from a FileReader.
d. You can directly write longs and shorts to a FileWriter.

Answer : a)


  1. What type of data would you read from the java.io.DataInputStream class ?

a. Reference type
b. Primitive type
c. Objects
d. Function

Answer : b)


  1. How many bytes does the following code write to file dest ?

try
{
FileOutputStream fos = new FileOutputStream (“dest”);
DataOutputStream dos = new DataOutputStream (fos);
dos.writeInt(3);
dos.writeDouble(0.0001);
dos.close ( );
fos.close( );
}

a. 2
b. 8
c. 12
d. 16

Answer : c)


  1. A file created with the following code:

FileOutputStream fos = new FileOutputStream (“datafile”);
DataOutputStream dos = new DataOutputStream (fos);
for(int i= 0; i<500; i++)
dos.writeInt(i);

a.Construct a FileInputStream, passing the name of the file. Onto the FileInputStream, chain a DataInputStream, and call it readInt( ) method.

b. Constructor a FileReader, passing the name of the file. Call the file reader’s readInt ( ) method.

c. Constructor a PipedInputStream, passing the name of the file. Call the piped input stream’s readInt( ) method.

d.Constructor a FileWriter, passing the name of the file. Onto the FileWriter, chain a DataInputStream, and call it readInt ( ) method.

Answer : a)


  1. Which of the following is true?

a. You cannot directly read text from a FileReader.
b. You can directly write text to a FileWriter.
c. You can directly read ints and floats from a FileReader.
d. You can directly write longs and shorts to a FileWriter.

Answer : b)


  1. A java stream is :

a. The flow of control through a function.
b. Associated with a particular class
c. A file.
d. A flow of data from one place to another.

Answer : d)


  1. Consider square number defined as follows:

square (1) = 1
square (N) = square (N-1)+2N-1
According to this definition, what is square(3)?

a. square (3) =  square (2) + square (1)
b. square (3) =  square (2) – 2*3 + 1
c. square (3) =  square (2) + 2*3 – 1
d. square (3) =  square (3) + 2*3 – 1

Answer : c)
Java MCQ Set-4 Explanation


  1. Look at the square numbers one more time:

square (1) = 1
square (N) = square (N-1) + 2N-1

Assume the definition has been implemented correctly. How many invocations will there be on the call stack if main ( ) calls square (5)?

a. 1
b. 3
c. 5
d. 6

Answer : c)
Java MCQ Set-4 Explanation


  1. When creating a subclass, what keyword is used to include a superclass?

a. extends
b. static
c. this
d. implement

Answer : a)


  1. How does a subclass execute its superclass constructor?

a. static ( )
b. super( )
c. this ( )
d. extends ( )

Answer : b)


Leave a Comment

Your email address will not be published. Required fields are marked *