Assignment - 7 Solution
Assignment - 7 Solution
PROGRAMMING IN JAVA
Assignment7
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________
QUESTION 1:
Which of these is a type of IO stream in Java?
a. Integer stream
b. Short stream
c. Byte stream
d. Character stream
Correct Answer: c, d
Detailed Solution:
Java defines only two types of streams: Byte stream and character stream. Others are not
streams.
QUESTION 2:
Which of the following is a class in java.io package?
a. FileReader
b. ObjectInput
c. ObjectOutput
d. DataInput
Correct Answer: a
Detailed Solution:
FileReader is a class in java.io package. All others are interfaces.
__________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
Consider the following program.
import java.io.*;
public class Question {
public static void main(String[] args)
{
try {
PrintWriter writer = new PrintWriter(System.out);
writer.write(64+'2');
writer.close();
}
catch (Exception e) {
System.out.println(e);
}
}
}
Correct Answer: d
Detailed Solution:
The expression 64+'2' add 64 with 50(i.e, Ascii value of 2)=114 and print
the corresponding char, in this case, r.
______________________________________________________________________________
QUESTION 4:
Consider the following program.
import java.io.*;
public class files
{
public static void main(String args[])
{
File obj = new File("java/programm/2023");
System.out.print(obj.getName());
}
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
a. java/programm/2023
b. java/programm/
c. java
d. 2023
Correct Answer: d
Detailed Solution:
Test by run.
______________________________________________________________________________
QUESTION 5:
Which method is used to read b length bytes from the input stream into an array?
Correct Answer: b
Detailed Solution:
public int read(byte[ ] b)throws IOException{} is used to read b length bytes from the input
stream into an array.
___________________________________________________________________________
QUESTION 6:
How many standard streams Java can support?
a. 2
b. 3
c. 4
d. 1
Correct Answer: b
Detailed Solution:
The Java platform supports three Standard Streams: Standard Input, accessed
through System.in; Standard Output, accessed through System.out; and Standard Error, accessed
through System.err.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
______________________________________________________________________________
QUESTION 7:
Which of the following stream is different from others?
a. System.in
b. System.out
c. PrintStream
d. FileOutputStream
Correct Answer: c
Detailed Solution:
Print stream is a virtual stream, which add functionality to already existing streams by wrapping
them in a new object. All others are physical streams (i.e., tied to some IO device that is
producing or consuming bytes or characters).
______________________________________________________________________________
QUESTION 8:
Which of the following is used to read a string from the input stream?
a. get( )
b. readLine( )
c. getLine( )
d. read( )
Correct Answer:b
Detailed Solution:
readLine() : Reads the next line of text from the input stream and return it as a String.
______________________________________________________________________________
QUESTION 9:
Which of the following class(es) can be used for handling files in Java?
a. java.files
b. java.io.File
c. java.io
d. java.Filehandling
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: b
Detailed Solution:
__________________________________________________________________
QUESTION 10:
Which of the following statement(s) is/are true?
a. The default delimiters for a Scanner object are the white space characters.
b. The Scanner class has instance methods for reading each of the Java primitive types
except char.
c. The Scanner methods do not throw any checked exceptions.
d. The Scanner class can be found in the java.util package.
Correct Answer: a, b, c, d
Detailed Solution: