250+ TOP MCQs on Input & Output Basics and Answers

Java MCQs on creating threads in Java Programming Language.

1. What does AWT stands for?
a) All Window Tools
b) All Writing Tools
c) Abstract Window Toolkit
d) Abstract Writing Toolkit

Answer: c
Clarification: AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.

2. Which of these is used to perform all input & output operations in Java?
a) streams
b) Variables
c) classes
d) Methods

Answer: a
Clarification: Like in any other language, streams are used for input and output operations.

3. Which of these is a type of stream in Java?
a) Integer stream
b) Short stream
c) Byte stream
d) Long stream

Answer: c
Clarification: Java defines only two types of streams – Byte stream and character stream.

4. Which of these classes are used by Byte streams for input and output operation?
a) InputStream
b) InputOutputStream
c) Reader
d) All of the mentioned

Answer: a
Clarification: Byte stream uses InputStream and OutputStream classes for input and output operation.

5. Which of these classes are used by character streams for input and output operations?
a) InputStream
b) Writer
c) ReadStream
d) InputOutputStream

Answer: b
Clarification: Character streams uses Writer and Reader classes for input & output operations.

6. Which of these class is used to read from byte array?
a) InputStream
b) BufferedInputStream
c) ArrayInputStream
d) ByteArrayInputStream

Answer: d
Clarification: None.

7. What will be the output of the following Java program if input given is ‘abcqfghqbcd’?

  1.     class Input_Output
  2.     {
  3.         public static void main(String args[]) throws IOException
  4.         {	 
  5.             char c;
  6.             BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
  7.             do
  8.             {
  9.                 c = (char) obj.read();
  10. 	        System.out.print(c);
  11.             } while(c != 'q');
  12.         }
  13.     }

a) abcqfgh
b) abc
c) abcq
d) abcqfghq

Answer: c
Clarification: None.
Output:

$ javac Input_Output.java
$ java Input_Output
abcq

8. What will be the output of the following Java program if input given is “abc’def/’egh”?

  1.     class Input_Output
  2.     {
  3.         public static void main(String args[]) throws IOException
  4.         {	 
  5.             char c;
  6.             BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
  7.             do 
  8.             {
  9.                 c = (char) obj.read();
  10. 	        System.out.print(c);
  11.             } while(c!=''');
  12.         }
  13.     }

a) abc’
b) abcdef/’
c) abc’def/’egh
d) abcqfghq

Answer: a
Clarification: ’ is used for single quotes that is for representing ‘ .
Output:

$ javac Input_Output.java
$ java Input_Output
abc'

9. What will be the output of the following Java program?

  1.     class output
  2.     {
  3.         public static void main(String args[])
  4.         { 
  5.              StringBuffer c = new StringBuffer("Hello");
  6.              System.out.println(c.length());
  7.         }
  8.     }

a) 4
b) 5
c) 6
d) 7

Answer: b
Clarification: length() method is used to obtain length of StringBuffer object, length of “Hello” is 5.
Output:

$ javac output.java
$ java output
5

  250+ TOP MCQs on Java’s Built in Exceptions and Answers

Leave a Comment

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

Scroll to Top