Week-04Assignment MCQ
Week-04Assignment MCQ
PROGRAMMING IN JAVA
Assignment 4
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________
QUESTION 1:
Which of the following is/are NOT correct regarding packages in Java?
Correct Answer: d
Detailed Solution:
A package is a namespace that organizes a set of related classes and interfaces. It is just like a
folder in your computer, where, you might keep HTML pages in one folder, images in another,
and scripts or applications in yet another. Since, Java programs can be composed of hundreds or
thousands of individual classes, it makes sense to keep things organized by placing related classes
and interfaces into packages.
____________________________________________________________________________
QUESTION 2:
Which of the following access specifier(s) should you choose if you need access restricted to
only subclass in the same package or different package?
a. default
b. public
c. protected
d. private
Correct Answer: c
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Detailed Solution:
In Java, same package subclass is accessible with default, protected and public access specifiers.
And, subclass of different package is accessible by protected and public access specifiers. So, in
this case we should choose protected only, as with public access specifier even non-subclass of
different package will also get access, which is not acceptable.
____________________________________________________________________________
QUESTION 3:
What is the significance of the ‘*’ in the following line, where “package” denotes a name of
a package?
import package.*;
Correct Answer: c
Detailed Solution:
The significance of ‘*’ in an import statement in Java is that all the classes and interfaces of this
package will be imported but not the sub-packages.
____________________________________________________________________________
QUESTION 4:
Which of the following statement(s) is (are) CORRECT regarding an interface in Java?
a. An interface can contain only abstract methods and standard methods but no static
methods are allowed.
b. Method bodies in an interface doesn’t exist for default methods and abstract methods.
c. An interfaces cannot be instantiated but can be implemented by classes.
d. An interfaces cannot be instantiated but can be extended by other interfaces.
Correct Answer: c, d
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Detailed Solution:
In the Java programming language, an interface is a reference type, similar to a class, which can
contain only constants, method signatures, default methods, static methods, and nested types.
Method bodies exist only for default methods and static methods. Interfaces cannot be
instantiated—they can only be implemented by classes or extended by other interfaces.
____________________________________________________________________________
QUESTION 5:
How Java Runtime Environment (JRE) knows where to look for a package that you create?
Correct Answer: a, b, c
Detailed Solution:
• First, by default, the Java run-time system uses the current working directory as its starting
point. Thus, if your package is in a sub-directory of the current directory, it will be found.
• Second, you can specify a directory path or paths by setting the CLASSPATH
environmental variable.
• Third, you can use the -classpath option with java and javac to specify the path to your
classes.
______________________________________________________________________________
QUESTION 6:
Multiple inheritance in Java is achieved by
a. Encapsulation
b. Interface
c. Packages
d. Multithreading
Correct Answer: b
Detailed Solution:
Java does not support multiple inheritance as C++ supports but Java supports an alternative
approach to this OOP feature known as interface.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
______________________________________________________________________________
QUESTION 7:
A platform is the hardware or software environment in which a program runs. Which of the
following is/are Java platform component(s)?
a. HTML
b. Java Virtual Machine
c. Java Application Programming Interface (API)
d. HotJava
Correct Answer: b, c
Detailed Solution:
A platform is the hardware or software environment in which a program runs. Some of the most
popular platforms are Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can
be described as a combination of the operating system and underlying hardware. The Java platform
differs from most other platforms in that it's a software-only platform that runs on top of other
hardware-based platforms.
Correct Answer: a
Detailed Solution:
In if statement, as a condition, it will take only boolean expression or boolean value.
________________________________________________________________
QUESTION 9:
Which of the following statement(s) is/are NOT true?
a. The default package in the Java language is java.lang.
b. String is a final class and it is present in java.lang package.
c. FileWriter is a class present in java.util package.
d. Thread is a class present in java.lang package.
Correct Answer: c
Detailed Solution:
QUESTION 10:
Which of the following interfaces is/are NOT a member of java.io package?
a. DataInput
b. ObjectInput
c. Runnable
d. FileFilter
Correct Answer: c
Detailed Solution:
Runnable is defined in java.lang package, and the other interfaces are defined in java.io package.
________________________________________________________________
************END************