Java Multiple Choice Questions & Answers on Input & Output Basics for Freshers

1. What does AWT stands for?

a) All Window Tools
b) All Writing Tools
c) Abstract Window Toolkit
d) Abstract Writing Toolkit
Answer: c

Explanation: 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

Explanation: 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

Explanation: 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

Explanation: 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

Explanation: 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
7. What is the output of this program if input given is ‘abcqfghqbcd’?
  1.     class Input_Output {
  2.         public static void main(String args[]) throws IOException {  
  3.             char c;
  4.             BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
  5.             do {
  6.                 c = (char) obj.read();
  7.          System.out.print(c);
  8.             } while(c != 'q');
  9.         }
  10.     }
a) abcqfgh
b) abc
c) abcq
d) abcqfghq
Answer: c
8. What is the output of this program if input given is “abc’def/’egh”?
  1.     class Input_Output {
  2.         public static void main(String args[]) throws IOException {  
  3.             char c;
  4.             BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
  5.             do {
  6.                 c = (char) obj.read();
  7.          System.out.print(c);
  8.             } while(c!='\'');
  9.         }
  10.     }
a) abc’
b) abcdef/’
c) abc’def/’egh
d) abcqfghq
Answer: a

Explanation: \’ is used for single quotes that is for representing ‘ .
9. What is the output of this program?
  1.     class output {
  2.         public static void main(String args[])
  3.         { 
  4.              StringBuffer c = new StringBuffer("Hello");
  5.              System.out.println(c.length());
  6.         }
  7.     }
a) 4
b) 5
c) 6
d) 7
Answer: b

Explanation: length() method is used to obtain length of StringBuffer object, length of “Hello” is 5.
10. What is the output of this program?
  1.     class output {
  2.         public static void main(String args[])
  3.         { 
  4.            StringBuffer s1 = new StringBuffer("Hello");
  5.            StringBuffer s2 = s1.reverse();
  6.            System.out.println(s2);
  7.         }
  8.     }
a) Hello
b) olleH
c) HelloolleH
d) olleHHello
Answer: b

Explanation: reverse() method reverses all characters. It returns the reversed object on which it was called.

Related

Java Multiple Choice Questions & Answers on Event Listeners Interfaces for Freshers

1. Which of these packages contains all the event handling interfaces? a) java.langb) java.awtc) java.awt.eventd) java.event Answer: c 2. Which of these interfaces handles the event when a compon...

Java Multiple Choice Questions & Answers on MouseEvent, TextEvent & WindowEvent Class for Freshers

1. Which of these events is generated when the a window is closed? a) TextEventb) MouseEventc) FocusEventd) WindowEvent Answer: d Explanation: A WindowEvent is generated when a window is opened, ...

Java Multiple Choice Questions & Answers on ComponentEvent, Container Event & FocusEvent Class for Freshers

1. Which of these events is generated when the size os an event is changed? a) ComponentEventb) ContainerEventc) FocusEventd) InputEvent Answer: a Explanation: A ComponentEvent is generated when ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item