arrow
arrow
arrow
Which keyword is used in Java to implement inheritance?
Question



Which keyword is used in Java to implement inheritance?

A.

extends

B.

inherits

C.

implements

D.

More than one of the above

E.

None of the above

Correct option is A


In Java, inheritance is a fundamental object-oriented programming (OOP) concept that allows a class to inherit properties and methods from another class. The keyword  extends is used to implement inheritance in Java, enabling a subclass to inherit from a superclass. This promotes code reusability and establishes a hierarchical relationship between classes. Therefore, the correct answer is (a) extends.
Important Key Points:
1. Inheritance in Java:
· Inheritance allows a class (subclass) to inherit fields and methods from another class (superclass).
· It promotes code reusability and establishes an "is-a" relationship between classes.
2. Keyword extends:
· The extends keyword is used to create a subclass that inherits from a superclass.
· Example:
class Animal { }
class Dog extends Animal { }
· Here, Dog inherits from Animal.
2. Other Keywords:
· inherits: Not a valid keyword in Java.
· implements: Used to implement interfaces, not inheritance.
Knowledge Booster:
· Types of Inheritance in Java:
· Single inheritance: A class inherits from one superclass.
· Multilevel inheritance: A class inherits from a subclass, which in turn inherits from another superclass.
· Hierarchical inheritance: Multiple subclasses inherit from a single superclass.
· Java does not support  multiple inheritance (a class inheriting from multiple superclasses) to avoid complexity and ambiguity.
· The super keyword is used in Java to refer to the superclass's methods or constructors.
· Inheritance is a key feature of OOP, along with  encapsulationpolymorphism and  abstraction.

Free Tests

Free
Must Attempt

DSSSB PRT Full Mock - 01

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

Educational Psychology & Pedagogy - 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon15 Mins
languageIcon English
Free
Must Attempt

DSSSB PRT PYP Held on 7th March 2022 Shift 1

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
test-prime-package

Access ‘BPSC TRE (11-12)’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
368k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow