Generalization means multi classes can inherit same attributes from the same superclass.
“Generalization need to create program that can be customize in according with new requirements.”
Overriding
“The process were the subclass redefine the function of superclass is called overriding”
Example:
- Class Employee
- {
- Leave
- }
- Class Trainee
- {
- Leave (function)
- }
In OOP the base class (parent class) is actually a “superclass “and the derived class (child class) is a “subclass”.
A class that inherits or drives attributes from base class (parent class) or another class is called the “derived class (child class).”
Syntax for create derived class
- <Access-specifies> class <base-class>
- {
- Statement
- }
- Class<derived-class> :< base-class>
- {
- Statement
- }
- Each instance of the derived class includes its own attributes and all the attributes of the base class.
- Any change mode to the base class (super class) automatically changes the behavior of it subclass.
- Constructors are called in the order of “base to derived class”.
- Destructors are called in the order of “derived to base class”.
Example:
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace overriding
- {
- class Base
- {
- public Base() //assign construtor of base class
- {
- Console.WriteLine("Constructor of Base Class:");
- }
- ~Base() //assign destrutor of base class
- {
- Console.WriteLine("Destructor of Base Class:");
- Console.ReadLine();
- }
- class derived : Base
- {
- public derived() //assign constructor of derived class
- {
- Console.WriteLine("Contructor of Dervived Class:");
- }
- ~derived() //assign destructor of derived class
- {
- Console.WriteLine("Destructor of Derived Class:");
- Console.ReadLine();
- }
- }
- class Basederived
- {
- static void Main(string[] args)
- {
- derived dr = new derived();
- Console.ReadLine();
- }
- }
- }
- }


Join the conversation! Your thoughts help the community grow.