C# Group Assignment
What is inheritance?
Inheritance is a fundamental concept in object-oriented programming that allows a
child class to inherit the properties from the superclass
The new class inherits the properties and methods of the existing class and can also
add new properties and methods of its own.
Inheritance promotes code reuse, simplifies code maintenance and improves code
organization.
Derived Class: The class that inherits the other class is known as a subclass(Derived
class, extended class or child class).The subclass can add its fields and methods in
addition to the superclass properties.
Parent Class: The class whose features are inherited is known as SuperClass(base
class or parent class).
Example:
The output will be: Eating
Barking
C# Group Assignment
Types of inheritance
In C#, inheritance is a key concept in object-oriented programming (OOP) that allows
you to create a new class (derived class) based on an existing class (base class). C#
supports several types of inheritance:
1. Single Inheritance: This is when a class inherits from only one base class.
Example:
2. Multilevel Inheritance: This is when a class is derived from another derived
class.
Example:
C# Group Assignment
3. Hierarchical Inheritance: This is when multiple classes inherit from a single
base class.
Example:
4. Interface Inheritance: This is when a class inherits from an interface (or multiple
interfaces). C# supports multiple inheritance through interfaces, meaning a class
can implement multiple interfaces.
Example:
C# Group Assignment
Note: that C# does not support multiple inheritance for classes (i.e., a class cannot inherit
from more than one base class), but it does support multiple interface inheritance.
Polymorphism
Polymorphism means "many forms", and it occurs when we have many classes that
are related to each other by inheritance.
Inheritance inherit fields and methods from another class. Polymorphism uses those
methods to perform different tasks. This allows us to perform a single action in
different ways.
There are two types of polymorphism: compile-time (method overloading) and run-
time (method overriding).
A. Compile-time Polymorphism (Method Overloading)
This occurs when multiple methods in the same class have the same name but
different parameters (number or type of parameters).
Example:
B. Run-time Polymorphism (Method Overriding)
This occurs when a derived class has a method with the same name and signature as a
method in the base class, and the derived class can provide a specific implementation
for that method.
C# Group Assignment
Example:
Group Name Id
1,Nardos Walelegn 15,115/23
2,Natnael Mulugeta 15,157/23
3,Natan Hailu 16,003/23
4,Shkur Ahmed 15,123/23
5,Eyuel Alemayehu 15,036/23