Correct option is A
Inheritance is a core concept of
Object-Oriented Programming (OOP) that allows a class (known as a
derived class or
subclass) to
inherit properties (attributes) and behaviors (methods) from another class (called the
base class or
superclass). This mechanism promotes
code reuse and the creation of hierarchical relationships between classes. Therefore, the correct answer is
(a) Inherit properties and behavior from another class.
Important Key Points:
1.
Inheritance Concept:
· Inheritance allows
one class to acquire the attributes and methods of another class.
· This supports
hierarchical class relationships, for example, Animal class with derived classes like Dog and Cat.
2.
Types of Inheritance:
·
Single Inheritance: One class inherits from one base class.
·
Multiple Inheritance: One class inherits from
more than one base class (supported in languages like C++).
·
Multilevel Inheritance: A derived class inherits from another derived class.
·
Hierarchical Inheritance: Multiple derived classes inherit from a single base class.
3.
Benefits of Inheritance:
· Promotes
code reuse.
· Supports the creation of
general-to-specific relationships.
· Facilitates
extensibility, where new functionality can be added to derived classes without modifying the base class.
Knowledge Booster:
· Inheritance supports the "is-a" relationship — for example, a Car is a Vehicle.
· In languages like Java, Python, and C++, inheritance is implemented using keywords like extends or class subclass : public superclass.
· Inheritance supports polymorphism, where a base class reference can point to a derived class object.
· In some programming languages, interfaces or abstract classes provide a form of inheritance focused only on method definitions.
· Object-Oriented design principles like SOLID leverage inheritance for the Open/Closed Principle (open for extension, closed for modification).
·
Creating instances of another class is a general
object creation process (instantiation), not specific to inheritance.
·
Overriding methods is part of
polymorphism, not inheritance directly. However, method overriding often occurs
within inherited classes, but it's not the defining purpose of inheritance.