NPTEL Programming In Java Week 4 Assignment Answers 2024
1. Which is the keyword used to specify the default access modifier in java?
a. default
b. DEFAULT
c. package
d. “There is no keyword”
Answer: d
Explanation: In Java, the default access modifier does not have a specific keyword. If no access modifier is mentioned, it is considered “default” (package-private). Hence, there’s no keyword to explicitly declare it.
2. What is the output of the Java program with access modifiers?

a. FOUR
b. Runtime Error
c. null
d. Compiler Error
Answer: d
Explanation: If access modifiers are used improperly or violate encapsulation, the compiler throws an error, preventing the code from executing.
3. What is the output of the below Java Code Snippet with access modifiers?

a. Weeks = 0
b. Weeks = 12
c. No Error, blank output
d. Compiler error
Answer: b
Explanation: Assuming the code correctly sets the value of Weeks
to 12 and has appropriate access, it will print Weeks = 12
.
4. Which of the following is the correct representation of access modifiers in order of increasing visibility?
a. private < default < protected < public
b. private < protected < default < public
c. public < protected < default < private
d. protected < default < private < public
Answer: a
Explanation: The correct visibility order is:
private < default (package-private) < protected < public
5. Which of the following package stores all the standard java classes?
a. java.util
b. java.lang
c. java.java
d. java.packages
Answer: b
Explanation: java.lang
contains core classes like Object
, String
, System
, etc., and is automatically imported.
6. Which of the following is/are true about packages in Java?
- Every class is part of some package.
- All classes in a file are part of the same package.
- If no package is specified, the classes in the file go into a special unnamed package.
- If no package is specified, a new package is created with folder name of class and the class is put in this package.
a. Only 1, 2 and 3
b. Only 1, 2 and 4
c. Only 4
d. Only 1 and 3
Answer: a
Explanation: Statements 1, 2, and 3 are correct. There is no automatic creation of a named package based on folder name.
7. What is the output of following Java program?

a. Compiler Error
b. Runtime Error
c. Welcome!
d. None of the above
Answer: c
Explanation: The program runs without error and prints “Welcome!”, meaning all access rules are properly followed.
8. Which of these access specifiers can be used for an interface?
a. Public
b. Protected
c. private
d. All of the mentioned
Answer: a
Explanation: Interfaces in Java can only be public or package-private (default). They cannot be private or protected.
9. Which of the following is the correct way of implementing an interface salary by class manager?
a. class Java extends NPTEL {}
b. class Java implements NPTEL {}
c. class Java imports NPTEL {}
d. none of the mentioned
Answer: b
Explanation: A class implements an interface using the implements
keyword. extends
is for classes or abstract classes.
10. What will be the output of the following Java program?

a. 0
b. 2
c. 4
d. Compiler Error
Answer: c
Explanation: If the code performs a loop or calculation leading to 4, and there’s no syntax error, it will output 4.