Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CsharpCourse
- {
- /*
- [ virtual members ]
- - always need implementation
- - not necessary to override it into all children
- - you can use it with base.funName()
- [ protected members ]
- - visible to its children
- [ protected internal ]
- */
- public abstract class animal
- {
- protected string Name;
- public animal()
- {
- Name = string.Empty;
- }
- public virtual void sound()
- {
- Console.WriteLine("The sound of animal");
- }
- }
- public class cat : animal // inheritance
- {
- public cat()
- {
- Name = "Basbosa";
- }
- public override void sound() // override the virtual method
- {
- base.sound();
- Console.WriteLine("Meow\n");
- }
- }
- public class dog : animal
- {
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- animal animal = new cat();
- animal.sound(); // call the method in cat class
- cat obj = new cat();
- obj.sound();
- dog obj2 = new dog();
- obj2.sound();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement