Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CsharpCourse
- {
- // abstract class
- public abstract class animal
- {
- public abstract void sound();
- }
- public class cat : animal // inheritance
- {
- public override void sound() // override the abstract method
- {
- Console.WriteLine("Meow");
- }
- }
- public class dog : animal
- {
- public override void sound()
- {
- Console.WriteLine("Hoof");
- }
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- // animal obj = new animal(); xxx
- animal obj = new cat();
- obj.sound();
- obj = new dog();
- obj.sound();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement