Inheritance in Java
Inheritance in Java - Important Points
1. | Which keyword is used in Java to implement inheritance? |
---|
A. super
B. this
C. extends
D. implements
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The 'extends' keyword is used in Java to implement inheritance.
2. | Which type of inheritance allows a class to inherit properties and behavior from multiple parent classes? |
---|
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
View Answer Discuss Work SpaceAnswer: option b
Explanation:
Multiple inheritance allows a class to inherit properties and behavior from multiple parent classes.
3. | Which access modifier allows a subclass to access the protected members of its parent class? |
---|
A. private
B. public
C. protected
D. default
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The 'protected' access modifier allows a subclass to access the protected members of its parent class.
4. | Which keyword is used to prevent a class from being inherited by other classes? |
---|
A. abstract
B. final
C. static
D. synchronized
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The 'final' keyword is used to prevent a class from being inherited by other classes.
5. | What is the first method that is executed when an object of a class is created? |
---|
A. finalize()
B. constructor
C. main()
D. start()
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The constructor is the first method that is executed when an object of a class is created.