Question 1
EasyWhat is inheritance?
- A.
Hiding data in a class
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is inheritance?
Hiding data in a class
Calling a function many times
Creating many objects
A class acquiring the properties and methods of another class
Answer: D
A subclass (child) reuses and extends the behaviour of a superclass (parent).
Which keyword is used for inheritance in Java?
inherits
extends
implements
super
Answer: B
class Dog extends Animal. Classes implement interfaces.
Which relationship does inheritance model?
HAS-A
USES-A
PART-OF
IS-A
Answer: D
A Dog IS-A Animal. HAS-A relationships are modelled with composition.
What does the 'super' keyword do in Java?
Refers to the parent class, e.g. to call its constructor or methods
Makes a method static
Ends inheritance
Creates a super user
Answer: A
super(...) calls the parent constructor; super.method() calls the parent's version of a method.
Does Java allow a class to extend more than one class?
Only abstract classes can
No, only single inheritance of classes is allowed
Yes, but only two
Yes, any number
Answer: B
Java avoids the diamond problem by allowing one superclass; a class can implement many interfaces.
Which type of inheritance has one parent class and several child classes?
Hybrid
Hierarchical
Multiple
Multilevel
Answer: B
Hierarchical: Shape → Circle, Square, Triangle. Multilevel: A → B → C.
What is the output of this code?
#include <iostream>
using namespace std;
class Base {
public:
Base() { cout << "Base "; }
};
class Derived : public Base {
public:
Derived() { cout << "Derived"; }
};
int main() {
Derived d;
return 0;
}
Base
Base Derived
Answer: B
Creating a derived object runs the base-class constructor first, then the derived one.
In inheritance, what is the class being inherited from called?
The base (parent or super) class
The child class
The friend class
The derived class
Answer: A
The class that inherits is the derived (child or sub) class.
In inheritance, what is the class that inherits called?
The base class
The abstract class
The super class
The derived (child or sub) class
Answer: D
It receives the members of the base class and can add or change behaviour.
What is single inheritance?
Only one object can be created
A class inherits from exactly one parent class
A class has only one method
A class inherits from itself
Answer: B
For example, Dog extends Animal.
Derived
Derived Base