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

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?
  1.     import java.io.*;
  2.     class files {
  3.         public static void main(String args[]) {
  4.             File obj = new File("/java/system");
  5.             System.out.print(obj.getName());
  6.         }
  7.     }
a) java
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?
  1.     import java.io.*;
  2.     class files {
  3.         public static void main(String args[]) {
  4.             File obj = new File("/java/system");
  5.             System.out.print(obj.getAbsolutePath());
  6.         }
  7.     }
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?
  1.     import java.io.*;
  2.     class files {
  3.         public static void main(String args[]) {
  4.             File obj = new File("/java/system");
  5.             System.out.print(obj.canWrite());
  6.             System.out.print(" " + obj.canRead());
  7.         }
  8.     }
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?
  1.     import java.io.*;
  2.     class files {
  3.         public static void main(String args[]) {
  4.             File obj = new File("/java/system");
  5.             System.out.print(obj.getParent());
  6.             System.out.print(" " + obj.isFile());
  7.         }
  8.     }
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

Related

C# Questions & Answers on Interfaces Introduction for Freshers

1. Which statement correctly defines Interfaces in C#.NET? a) Interfaces cannot be inheritedb) Interfaces consists of data static in nature and static methodsc) Interfaces consists of only method d...

C# Questions & Answers on Abstract Class & Methods for Freshers

1. A type of class which does not have its own objects but acts as a base class for its subclass is known as? a) Static classb) Sealed classc) Abstract classd) None of the mentioned Answer: c 2. ...

C# Questions & Answers on Constructor Overloading for Freshers

1. What will be the output of the given set of code? class maths { public int length; public int breadth; public maths(int x, int y) { length = x; ...

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