Week 04 Assignment
Week 04 Assignment
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 the correct statement for creating a package?
a. <package name> package;
b. package <package name>;
c. package;
d. <package name>;
Correct Answer: b
Detailed Solution:
To define a package, every source file needs to start with the statement ‘package’ followed
by the package name.
_____________________________________________________________
QUESTION 2:
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.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
Which of the following statement(s) is/are false?
a. Java packages are hierarchical.
b. System.out.println() is a predefined java function.
c. Java can have a nested class structure.
d. The Java static keyword is a non-access modifier.
Correct Answer: a
Detailed Solution:
At first, packages appear to be hierarchical, but they are not. For example, the Java API includes
a java.awt package, a java.awt.color package, a java.awt.font package, and many others that begin
with java.awt. However, the java.awt.color package, the java.awt.font package, and other
java.awt.xxxx packages are not included in the java.awt package. The prefix java.awt (the Java
Abstract Window Toolkit) is used for a number of related packages to make the relationship
evident, but not to show inclusion. All the other options are correct.
___________________________________________________________________________
QUESTION 4:
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.
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 5:
Correct Answer: a
Detailed Solution:
Test by run.
The static import statement is used to import the static members (e.g., PI) of java.lang.Math.
import static java.lang.Math.*;
____________________________________________________________________________
QUESTION 6:
Which of the following is the minimum requirement for executing a Java program?
a. JDK
b. JRE
c. JDK without JRE
d. JRE without JDK
Correct Answer: b, d
Detailed Solution:
JRE (Java Runtime Environment) is required for the execution of the Java programs. JDK contains
JRE by default. Therefore, if we talk about minimum requirement, then both b and d options are
correct.
___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 7:
Which of the following is required for developing a Java program?
a. JDK
b. JRE
c. JDK without JRE
d. JRE without JDK
Correct Answer: a
Detailed Solution:
JDK (Java Development Kit) is required for developing the Java programs. Since, JDK already
comes packed with JRE and there is no option to select JDK without JRE, option a is the only
valid option.
_____________________________________________________________________________
QUESTION 8:
Which of the following is/are valid declaration(s) of an interface?
}
}
Detailed Solution:
In option (a), It has a method implementation in it. Only default and static methods have
implementations. So, option (a) is not a valid interface. All others are valid.
_____________________________________________________________________________
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. Runnable is a class present in java.lang package.
d. Thread is a class present in java.lang package.
Correct Answer: c
Detailed Solution:
QUESTION 10:
Which of the following statement(s) is/are true?
a. With the import statement, generally import only a single package member or an entire
package.
b. To import all the types contained in a particular package, use the import statement with
the asterisk (*) wildcard character.
import package.*;
c. import package.A*; it used to match a subset of the classes in a package starts with “A”.
d. import package.A*; it generates compilation error.
Detailed Solution:
import package.A*; it generates compilation error.
************END************