

Inheritance -OOP
Presentation
•
Information Technology (IT)
•
•
Practice Problem
•
Hard
Prosper Yeng
FREE Resource
10 Slides • 0 Questions
1
INT201: Object-Oriented Programming – Inheritance (C#)
By Dr. Prosper Yeng
2
Learning Objectives (Aligned with Bloom’s Taxonomy).By the end of this lesson, students will be able to:
Revise on the concepts of object, and class
Define inheritance in object-oriented programming.
Explain how inheritance enables code reusability and hierarchical class relationships.
Demonstrate single and multilevel inheritance in C# through practical code examples (e.g., Car → ElectricCar)
Differentiate between various types of inheritance
3
1. What Is an Object?
An object is a real-world entity that has data (attributes) and behavior (methods).
Example: A Car object has:
brand = Toyota
color = red
speed = 120
Methods: Start(), Stop()
Objects are created from templates or blueprints called classes.
4
2. What Is a Class?
A class is a blueprint that defines what data and actions its objects can have.
Example:
public class Car {
public string brand;
public int speed;
public void Start() {
Console.WriteLine("Car started");
}
public void Stop() {
Console.WriteLine("Car stopped");
}
}
5
3. Creating an Object instance from a Class
Example:
Car myCar = new Car();
myCar.brand = "Toyota";
myCar.speed = 120;
myCar.Start();
Output:
Car started
6
Inheritance is an object-oriented programming (OOP) principle
Allows a new class (called the child or derived class)
To acquire the properties and behaviors of an existing class (called the parent or base class).
Example: ElectricCar inherits all properties from Car and adds new ones like ChargeBattery().
4. What Is Inheritance?
7
5. Example: Car → ElectricCar
public class Car {
public string brand;
public void Start()
{
Console.WriteLine("Car started");
}
}
public class ElectricCar : Car {
public int batteryLevel;
public void ChargeBattery()
{
Console.WriteLine("Battery charging...");
batteryLevel = 100;
}
}
8
6. Using the ElectricCar Class
ElectricCar myTesla = new ElectricCar();
myTesla.brand = "Tesla";
myTesla.Start(); // from Car
myTesla.ChargeBattery(); // from ElectricCar
Output:
Car started
Battery charging...
9
7. Calling Parent Method Using base
10
8.Recap
Object – real-world entity
Class – blueprint for objects
Inheritance – child uses parent’s code
Inheritance types
Next class:
base – calls parent method
override – modifies parent behavior
Inheritance type implementation
INT201: Object-Oriented Programming – Inheritance (C#)
By Dr. Prosper Yeng
Show answer
Auto Play
Slide 1 / 10
SLIDE
Similar Resources on Wayground
6 questions
Consumer Rights and Responsibilities
Presentation
•
9th - 12th Grade
10 questions
Making Predictions
Presentation
•
3rd - 4th Grade
10 questions
ORDER OF THE ADJECTIVES
Presentation
•
University
9 questions
Photosynthesis & Cellular Respiration EOC Questions (18.9)
Presentation
•
8th - 10th Grade
7 questions
COMMANDS
Presentation
•
5th Grade
10 questions
Chemical Formulas
Presentation
•
6th - 8th Grade
10 questions
Roman Republic
Presentation
•
6th Grade
8 questions
Intro to Poetry
Presentation
•
5th Grade
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade