MICRO PLANNING Summary 5 5 Recap Evocation 3














![4. HIERARCHICAL INHERITANCE class Program { static void Main(string[] args) { Principal g = 4. HIERARCHICAL INHERITANCE class Program { static void Main(string[] args) { Principal g =](https://slidetodoc.com/presentation_image_h2/5fab11f2b746437b1074d873295b7d90/image-15.jpg)







- Slides: 22
MICRO PLANNING Summary, 5 5 Recap, Evocation, 3 General Objective, 2 Mind map, 10 Specific Objective 1, 15 Discussion, 5 Specific objective 2, 10 Formative assessment, 5
ALPHA BREATHING
Evocation
INHERITANCE
GENERAL OBJECTIVE To explain about the Abstract class, Abstract method, Sealed Classes, Sealed Methods different types of inheritance and interface
SPECIFIC OBJECTIVE 1 To illustrate the Abstract Class, Abstract Method and Sealed Classes, Sealed Methods.
Abstract class and Abstract methods An abstract class cannot be instantiated Abstract methods cannot have implementation Its implementation must be provided in nonabstract derived classes by overriding the method It can be declared only in abstract classes
abstract class Base. Class { public abstract string Your. City(); } class Derived. Class : Base. Class { public override string Your. City() //It is mandatory to implement absract method { return "London"; } } class Program { static void Main(string[] args) { Derived. Class obj = new Derived. Class(); string city = obj. Your. City(); Console. Write. Line(city); } } O/P: London
Sealed classes and Sealed methods To prevent a class being derived further, it can be declared as sealed An attempt to inherit sealed classes will cause an error A sealed class cannot be an abstract class A method in the derived class cannot override a sealed method class A { public virtual void Fun() { … } } class B: A { public sealed override void Fun() { … }
SPECIFIC OBJECTIVE 2 To illustrate the 4 types of inheritance
TYPES OF INHERITANCE 1. 2. 3. 4. Simple inheritance Multilevel inheritance Hierarchical inheritance
1. SIMPLE INHERITANCE The derived class inherits the base class member variables and member methods. public class Parent { string parent. String; public Parent() { Console. Write. Line("Parent Constructor. "); } public Parent(string my. String) { parent. String = my. String; Console. Write. Line(parent. String); } public void print() { Console. Write. Line("I'm a Parent Class. "); } }
public class Child : Parent { public Child() : base("From Derived") { Console. Write. Line("Child Constructor. "); } public new void print() { base. print(); Console. Write. Line("I'm a Child Class. "); } public static void Main() { Child child = new Child(); child. print(); } I/P: From Derived Child Constructor. I'm a Parent Class. I'm a Child Class.
3. MULTILEVEL INHERITANCE class Head. Office { public void Head. Office. Address() { Console. Write. Line("Head Office Address"); } } class Branch. Office: Head. Office { public void Branch. Office. Address() { Console. Write. Line("Branch Office Address"); } } class Regonal. Office: Branch. Office { Public void Employee. List() { Console. Write. Line("Name of Employee"); } Public void Under. Branch. Office() { Console. Write. Line("Name of Branch Office: "); } }
4. HIERARCHICAL INHERITANCE class Program { static void Main(string[] args) { Principal g = new Principal(); g. Monitor(); Teacher d = new Teacher(); d. Monitor(); d. Teach(); Student s = new Student(); s. Monitor(); s. Learn(); Console. Read. Key(); } } class Principal { public void Monitor() { Console. Write. Line("Monitor"); } }
class Teacher : Principal { public void Teach() { Console. Write. Line("Teach"); } } class Student : Principal { public void Learn() { Console. Write. Line("Learn"); } } O/P: Monitor Teach Monitor Learn
Discussion
Mind map
Stimulating Questions 1. When you know the steps to build a multi storied building, how will you collect the details to build a 2 storied house?
Summary Abstract Class Abstract Method Sealed Class Sealed Methods Types of Inheritance Simple inheritance Multilevel inheritance Hierarchical inheritance
Formative Assessment 1. All C# applications begin execution by calling the _____ method. 1. Class() 2. Main() 3. Submain() 4. Namespace 2. A derived class can stop virtual inheritance by declaring an override as _______ 1. Inherits 2. Extends 3. Inheritable 4. sealed
Formative Assessment 3. In order for an instance of a derived class to completely take over a class member from a base class, the base class has to declare that member as _____ 1. 2. 3. 4. New Base Virtual Overloads 4. To change the implementation based on the type of object and not on the variable that we are using, we need to _______ the default implementation in our base class with the one in the derived class. 1. 2. 3. 4. Override Make it virtual Keep it constant Change