NPTEL Programming In Java Week 3 Assignment Answers 2024

Join Our WhatsApp Group Join Now
Join Us On Telegram Join Now

NPTEL Programming In Java Week 3 Assignment Answers 2024

1. Which of the following statement is true regarding the order of execution of constructors in an inheritance hierarchy?

a. Base class constructor will be called followed by the derived class constructor.
b. Derived class constructor will be called followed by the base class constructor.
c. Only Base class constructor will be called.
d. Only derived class constructor will be called.

Answer :- For Answer Click Here

2. The super() method is used to:

a. Call constructor of friend class
b. Is a declared method
c. Call constructor of the parent class
d. Call constructor

Answer :- For Answer Click Here

3. What will be the output of the following Java program?

NPTEL Programming In Java Week 3 Assignment Answers 2024

a. 0
b. 1
c. 2
d. Compilation Error

Answer :- For Answer Click Here

4. In Java, is it possible to override a static method?

a. Yes, we can override a static method just like we do with instance methods.
b. No, static methods cannot be overridden because they belong to the class, not the object.
c. It depends on whether the static method is declared as final or not.
d. It depends on the access modifier of the static method.

Answer :- 

5. What is the output of the following Java program?

NPTEL Programming In Java Week 3 Assignment Answers 2024

a. “The vehicle moves”
b. “The car moves”
c. The code does not compile
d. None of the above

Answer :- 

6. What is the output of the below Java program with inheritance?

NPTEL Programming In Java Week 3 Assignment Answers 2024

a. Sweet=$10 Sugar=$20
b. Sweet=$10 Sugar=$10
c. Sweet=$20 Sugar=$20
d. Compiler error

Answer :- For Answer Click Here

7. What is the purpose of method hiding in Java inheritance?

a. To prevent a subclass from inheriting methods
b. To override superclass methods with new implementations
c. To expose private methods of the superclass
d. To define methods with the same name in both the superclass and subclass

Answer :- 

8. What is the output of the following Java program?

NPTEL Programming In Java Week 3 Assignment Answers 2024

a. “parent from parent”
b. “child from child”
c. “parent from child”
d. “child from parent”

Answer :- 

9. Can a class be marked as both “final” and “abstract” in Java?

a. Yes, but only if it has no methods.
b. Yes, a class can be marked as both “final” and “abstract.”
c. No, a class cannot be both “final” and “abstract.”
d. Yes, but only if it is marked as “protected.”

Answer :- 

10. In Java, is it possible to override a static method?

a. Yes, we can override a static method just like we do with instance methods.
b. No, static methods cannot be overridden because they belong to the class, not the object.
c. It depends on whether the static method is declared as final or not.
d. It depends on the access modifier of the static method.

Answer :- For Answer Click Here