Java Questions and Answers Part-24

1. Which of these class is not a member class of java.io package?
a) String
b) StringReader
c) Writer
d) File

Answer: a
Explanation: String

2. Which of these interface is not a member of java.io package?
a) DataInput
b) ObjectInput
c) ObjectFilter
d) FileFilter

Answer: c
Explanation: ObjectFilter

3. Which of these class is not related to input and output stream in terms of functioning??
a) File
b) Writer
c) InputStream
d) Reader

Answer: a
Explanation: A File describes properties of a file, a File object is used to obtain or manipulate the information associated with a disk file, such as the permissions, time date, and directories path, and to navigate subdirectories.

4. Which of these is specified by a File object?
a) a file in disk
b) directory path
c) directory in disk
d) none of the mentioned

Answer: c
Explanation: directory in disk

5. Which of these is method for testing whether the specified element is a file or a directory?
a) IsFile()
b) isFile()
c) Isfile()
d) isfile()

Answer: b
Explanation: isFile() returns true if called on a file and returns false when called on a directory.

6. What will be the output of the following Java code?
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("/java/system");
System.out.print(obj.getName());
}
}
a) java
b) system
c) java/system
d) /java/system

Answer: b
Explanation: obj.getName() returns the name of the file.
Output:
system

7. Which of these classes is used for input and output operation when working with bytes?
a) InputStream
b) Reader
c) Writer
d) All of the mentioned

Answer: a
Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.

8. Which of these class is used to read and write bytes in a file?
a) FileReader
b) FileWriter
c) FileInputStream
d) InputStreamReader

Answer: c
Explanation: FileInputStream

9. Which of these method of InputStream is used to read integer representation of next available byte input?
a) read()
b) scanf()
c) get()
d) getInteger()

Answer: a
Explanation: read()

10. Which of these data type is returned by every method of OutputStream?
a) int
b) float
c) byte
d) none of the mentioned

Answer: d
Explanation: Every method of OutputStream returns void and throws an IOExeption in case of errors.