Java Multiple Choice Questions & Answers on Java.io package for Freshers

https://www.computersprofessor.com/2017/12/java-multiple-choice-questions-answers_14.html
1. Which of these packages contain classes and interfaces used for input & output operations of a program?
a) java.util
b) java.lang
c) java.io
d) All of the mentioned
Answer: c
Explanation: java.io provides support for input and output operations.
2. Which of these class is not a member class of java.io package?
a) String
b) StringReader
c) Writer
d) File
Answer: a
3. Which of these interface is not a member of java.io package?
a) DataInput
b) ObjectInput
c) ObjectFilter
d) FileFilter
Answer: c
4. 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.
5. 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
6. 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.
7. What is the output of this program?
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
b) system
c) java/system
d) /java/system
Answer: b
Explanation: obj.getName() returns the name of the file.
8. What is the output of this program?
import java.io.*;
class files {
public static void main(String args[]) {
File obj = new File("/java/system");
System.out.print(obj.getAbsolutePath());
}
}
Note: file is made in c drive.
a) java
b) system
c) java/system
d) /java/system
Answer: d
9. What is the output of this program?
import java.io.*;
class files {
public static void main(String args[]) {
File obj = new File("/java/system");
System.out.print(obj.canWrite());
System.out.print(" " + obj.canRead());
}
}
Note: file is made in c drive.
a) true false
b) false true
c) true true
d) false false
Answer: d
10. What is the output of this program?
import java.io.*;
class files {
public static void main(String args[]) {
File obj = new File("/java/system");
System.out.print(obj.getParent());
System.out.print(" " + obj.isFile());
}
}
Note: file is made in c drive.
a) java true
b) java false
c) \java false
d) \java true
Answer: c
Explanation: getparent() giver the parent directory of the file and isfile() checks weather the present file is a directory or a file in the disk