NPTEL Programming In Java Week 5 Assignment Answers 2022
Q1. Consider the following program.
If the program is executed, then what will be the output from the execution?
a. 100
102
b. 20
22
c. 102
100
d. 22
20
Answer: Option A
Q2. Consider the following program.
If the program is executed, then what will be the output from the execution?
a. 170
b. 130
c. 0
d. 260
Answer: a. 170
Q3. What is the output of the following code?
a. Output: This is Explanation’s Print method
This is Answer’s Print method
b. Error: ‘super.super‘ is not allowed.
c. Error: Compilation unsuccessful, as there is only one super class of Answer.
d. Output: This is Answer’s Print method
This is Explanation’s Print method
Answer: b. Error: ‘super.super‘ is not allowed.
Q4. Which of the following is/are interface(s)?
a. DriverManager
b. Connection
c. Statement
d. ResultSet
Answer: b. Connection
c. Statement
d. ResultSet
Q5. Which of the following statement(s) is/are true?
a. You can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.
b. You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.
c. A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in.
d. You cannot declare new methods in the subclass that are not in the superclass.
Answer: a. You can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.
b. You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.
c. A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in.
Q6. Which of the following statement(s) is/are true?
a. Static methods in interfaces are never inherited.
b. You will get a compile-time error if you attempt to change an instance method in the superclass to a static method in the subclass.
c. You can prevent a class from being sub classed by using the final keyword in the class’s declaration.
d. An abstract class can only be subclassed; it cannot be instantiated.
Answer: Option A, B, C, D.
Q7. Consider the following piece of code.
Which of the following statement(s) is/are correct?
a. There is no main () method so the program is not compile successfully.
b. The value of i will be printed as 22, as it is static and final by default.
c. The value of i will be printed as 2, as it is initialized in class B.
d. Compile time error.
Answer: a. There is no main () method so the program is not compile successfully.
Q8. Which of the following statement(s) is/are true?
a. A class can extend more than one class.
b. An interface can extend many interfaces.
c. An interface can implement many interfaces.
d. A class can extend one class and implement many interfaces.
Answer: b. An interface can extend many interfaces.
d. A class can extend one class and implement many interfaces.
Q9. All classes in Java are inherited from which class?
a. java.lang.class
b. java.class.inherited
c. java.class.object
d. java.lang.Object
Answer: d. java.lang.Object
Q10.
If the program is executed, then what will be the output from the execution?
a. Output: 1020
b. Output: 30
c. Output: 2010
d. Error: C1 is abstract; cannot be instantiated.
Answer: d. Error: C1 is abstract; cannot be instantiated.
Not 100% confirm
Comments
Post a Comment