Week-03Assignment MCQ
Week-03Assignment MCQ
PROGRAMMING IN JAVA
Assignment 3
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________
QUESTION 1:
Which of the following keyword(s) can be used in a subclass to call the constructor of super
class?
a. super
b. this
c. extent
d. extends
Correct Answer: a
Detailed Solution:
The keyword super is used to call the constructor of the super class from a subclass.
______________________________________________________________________
QUESTION 2:
If there is an abstract method in a class, then which of the following is/are NOT true.
Correct Answer: d
Detailed Solution:
If a class includes abstract methods, then the class should be declared abstract. No object can be
created for an abstract class. Further, if a class is derived from an abstract class and abstract method
in the base class is not defined, then the derived class is also an abstract class.
________________________________________________________________
QUESTION 3:
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.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
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.
Correct Answer: a
Detailed Solution:
On object creation of derived class, first base class constructor and then the derived class
constructor will be called.
______________________________________________________________________________
QUESTION 4:
Which of the following is TRUE about the break statement in Java in the context of loop?
Correct Answer: b
Detailed Solution:
A break statement inside a loop will terminate the loop execution and the control jumps to the
statement immediately after the last statement in the loop.
______________________________________________________________________________
QUESTION 5:
Which of the following is called when a method having the same name as that of the class is
defined?
a. abstract
b. this
c. final
d. constructor
Correct Answer: d
Detailed Solution:
In a class, if more than one method having the same name but with different signature is used,
then it is called a constructor.
___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 6:
Which of the following is NOT true about a method in a class?
Detailed Solution:
A constructor cannot be defined recursively. Other statements are true.
_____________________________________________________________________________
QUESTION 7:
public class B1 {
private static int i = 0;
private static int j = 0;
{
int j = 3;
System.out.println("i + j is "+i +j);
}
k = i + j;
System.out.println(k);
System.out.println(j);
}
}
What is the output of the above program?
a. i + j is 43
4
0
b. i + j is 7
9
3
c. i + j is 43
9
3
d. i + j is 7
2
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: a
_____________________________________________________________________________
QUESTION 8:
Which inheritance is NOT supported in Java programming?
Correct Answer: a
Detailed Solution:
Java does not support multiple inheritance of classes but it supports multiple inheritance for
interfaces. Means, a class cannot inherit more than one class but it can inherit and implement
multiple interfaces.
______________________________________________________________________________
QUESTION 9:
Which of the following data structure is used to manage the recursion in Java?
a. Array
b. Stack
c. Queue
d. Tree
Correct Answer: b
Detailed Solution:
A stack is internally used by the Java run time manager to execute a recursive method.
______________________________________________________________________
QUESTION 10:
Hiding internal data from the outside world, and accessing it only through publicly exposed
methods is known as data_______________
a. Polymorphism
b. Encapsulation.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
c. Inheritance.
d. Duplication.
Correct Answer: b
Detailed Solution: Hiding the internal details from the outside world is known as encapsulation.