0% found this document useful (0 votes)
15 views2 pages

Webx Experiment 3

This document explains inheritance in TypeScript, highlighting its role in object-oriented programming for code reuse and modularity. It discusses the concepts of parent and child classes, advantages of inheritance, types of inheritance, and method overriding. Real-world use cases are provided to illustrate the practical applications of inheritance in software development.

Uploaded by

Pranav bagal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Webx Experiment 3

This document explains inheritance in TypeScript, highlighting its role in object-oriented programming for code reuse and modularity. It discusses the concepts of parent and child classes, advantages of inheritance, types of inheritance, and method overriding. Real-world use cases are provided to illustrate the practical applications of inheritance in software development.

Uploaded by

Pranav bagal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 3

Aim:
Write a program in TypeScript to implement inheritance.

Theory

What is Inheritance in TypeScript?


Inheritance is a key feature of object-oriented programming (OOP) that allows a class to
derive properties and methods from another class. It provides a mechanism for code reuse,
reducing redundancy and enhancing modularity. In TypeScript, inheritance is achieved
using the 'extends' keyword, enabling a child class to inherit features from a parent class.

Parent and Child Classes


1. Parent Class (Super Class): A parent class is the base class that contains properties and
methods shared by multiple derived classes. It serves as a blueprint for its child classes,
ensuring consistency across implementations.

2. Child Class (Sub Class): A child class extends the parent class and inherits its properties
and methods. It can also introduce new attributes and behaviors or modify existing ones by
overriding methods from the parent class.

Advantages of Inheritance
- Code Reusability: Instead of writing the same code multiple times, common functionality
can be inherited from a parent class.

- Modularity: Breaking down complex systems into smaller, manageable components.

- Maintainability: Changes in the parent class automatically reflect in child classes, reducing
the need for code duplication.

- Extensibility: Allows new functionality to be added without modifying existing code,


following the Open-Closed Principle of software design.

Types of Inheritance in TypeScript


1. Single Inheritance: A child class inherits from one parent class.

2. Multilevel Inheritance: A child class inherits from another child class, forming a chain of
inheritance.

3. Hierarchical Inheritance: Multiple child classes inherit from a single parent class.
Method Overriding in Inheritance
When a child class redefines a method from the parent class to provide its own specific
implementation, it is called method overriding. This allows customization of inherited
behavior while maintaining a shared structure.

Real-World Use Cases


- User Management System: A base 'User' class can have properties like 'name' and 'email',
while 'Admin' and 'Customer' classes extend 'User' with additional functionalities.

- Animal Classification: A 'Mammal' class can define common traits, while subclasses like
'Dog' and 'Cat' extend it with specific behaviors.

- Banking Application: A 'BankAccount' class can define general account operations, while
'SavingsAccount' and 'CurrentAccount' extend it with unique features.

Conclusion
Inheritance in TypeScript is a powerful feature that enhances code reusability, modularity,
and maintainability. By defining a parent class and extending it to child classes, developers
can create structured and scalable applications. Understanding inheritance helps in building
robust OOP-based TypeScript applications.

You might also like