Input & Output Basics
Input & Output Basics
Input & Output Basics
This section of our 1000+ Java MCQs focuses on creating threads in Java Programming
Language.
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
View Answer
Answer: a
Explanation: Like in any other language, streams are used for input and output
operations.
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 and OutputStream
b) InputOutputStream
c) Reader
d) All of the mentioned
View Answer
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 and OutputStream
b) Writer and Reader
c) ReadStream and WriteStream
d) InputOutputStream
View Answer
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
View Answer
Answer: d
Explanation: None.
7. What will be the output of the following Java program if input given is
�abcqfghqbcd�?
class Input_Output
{
public static void main(String args[]) throws IOException
{
char c;
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
do
{
c = (char) obj.read();
System.out.print(c);
} while(c != 'q');
}
}
a) abcqfgh
b) abc
c) abcq
d) abcqfghq
View Answer
Answer: c
Explanation: 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�?
class Input_Output
{
public static void main(String args[]) throws IOException
{
char c;
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
do
{
c = (char) obj.read();
System.out.print(c);
} while(c!='\'');
}
}
a) abc�
b) abcdef/�
c) abc�def/�egh
d) abcqfghq
View Answer
Answer: a
Explanation: \� is used for single quotes that is for representing � .
Output:
advertisement
$ javac Input_Output.java
$ java Input_Output
abc'
9. What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
System.out.println(c.length());
}
}
a) 4
b) 5
c) 6
d) 7
View Answer
Answer: b
Explanation: length() method is used to obtain length of StringBuffer object,
length of �Hello� is 5.
Output:
$ javac output.java
$ java output