Lect 2.4.5 additional - CPE425/CSC301/SC433 Programming...

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

View Full Document Right Arrow Icon
CPE425/CSC301/SC433 rogramming Languages Programming Languages Lecture 2.4.5 xamples on Polymorphism 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 Document Right Arrow Icon
using System; namespace AbstractFunc { abstract class LivingThings { ublic irtual oid Grow( ) { class Class1 { tatic void Main( ) { public virtual void Grow( ) { Console.WriteLine("LivingThings grow!"); } public abstract void Speak( ); static void Main( ) { Dog mDog = new Dog( ); mDog.Speak( ); mDog.Move( ); Dog Eat ; base virtual, subclass either ‘override’ or ‘new’ } abstract class Mammal : LivingThings { public void Move( ) { Console.WriteLine("Mammal move!"); } mDog.Eat(); mDog.Grow(); Mammal m = new Dog( ); Compiler Warning eed to declare ‘ne ’ abstract, subclass must ‘override’ LivingThings public override void Grow() { Console.WriteLine("Mammal grow!"); } m.Speak( ); m.Move( ); m.Eat(); Grow ; Need to declare ‘new’ public void Eat() { Console.WriteLine("Mammal eat!"); } } lass og ammal // concrete class m.Grow(); Console.Read(); } Inherit this method Woof! Dog move! Mammal eat! og grow! class Dog : Mammal { public override void Speak( ) { Console.WriteLine("Woof!"); } public void Move( ) { } } Dog grow!
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Lect 2.4.5 additional - CPE425/CSC301/SC433 Programming...

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

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