NPTEL Programming In Java Week 4 Assignment Answers 2024
1. Which access modifier allows a method to be accessible within the same package but not from
outside the package?
a. default
b. private
c. public
d. protected
Answer :- For Answers Click Here
2. What will happen if you attempt to access a private method from another class in Java?
a. The method will be accessible.
b. The method will throw an exception.
c. The method will be inaccessible.
d. The method will be converted to protected.
Answer :-
3.

Answer :-
4. Which of the following is a built-in Java package?
a. java.util
b. my.package.util
c. default.package
d. system.java
Answer :-
5. What keyword is used to define a package in Java?
a. define
b. package
c. import
d. namespace
Answer :- For Answers Click Here
6. How do you import a specific class from a package in Java?
a. import package.*;
b. import package.ClassName;
c. include package.ClassName;
d. use package.ClassName;
Answer :-
7.

Answer :-
8. Which of the following is true about Java interfaces?
a. They cannot contain method implementations.
b. An interface can extend multiple classes.
c. An interface can only contain abstract methods.
d. They allow a class to achieve multiple inheritance.
Answer :-
9. What will happen if you do not specify an access modifier for a class in a package?
a. The class will be ‘private’ by default.
b. The class will be ‘protected by default.
c. The class will be accessible only within the same package.
d. The class will be ‘public’ by default.
Answer :-
10. Which access modifier provides the most restrictive access in Java?
a. default
b. protected
c. private
d. public
Answer :- For Answers Click Here