Lect 2.5 Examples_on_Polymorphism_MultipleInheritance_Student

Lect 2.5 Examples_on_Polymorphism_MultipleInheritance_Student

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 2.5 Examples on Polymorphism, Multiple Inheritance
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
using System; namespace AbstractFunc { abstract class LivingThings { public virtual void Grow( ) { Console.WriteLine("LivingThings grow!"); } public abstract void Speak( ); } abstract class Mammal : LivingThings { public void Move( ) { Console.WriteLine("Mammal move!"); } public override void Grow() { Console.WriteLine("Mammal grow!");} } public void Eat() { Console.WriteLine("Mammal eat!");} } class Dog : Mammal { // concrete class public override void Speak( ) { Console.WriteLine("Woof!"); } public void Move( ) { Console.WriteLine("Dog move!"); } public new void Grow( ) { Console.WriteLine("Dog grow!"); } 2 class Class1 { static void Main( ) { Dog mDog = new Dog( ); mDog.Speak( ); mDog.Move( ); mDog.Eat(); mDog.Grow(); Mammal m = new Dog( ); m.Speak( ); m.Move( ); m.Eat(); m.Grow(); Console.Read(); } } }
Background image of page 2
class Dog : Mammal { public override void Speak( ) { Console.WriteLine("Woof!"); } public void Move( ) { Console.WriteLine("Dog move!"); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Lect 2.5 Examples_on_Polymorphism_MultipleInheritance_Student

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online