Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CsharpCourse
- {
- /*
- [ Member Hiding / Shadowing ]
- */
- public abstract class animal
- {
- protected string Name;
- public animal()
- {
- Name = string.Empty;
- }
- public void sound()
- {
- Console.WriteLine("The sound of animal\n");
- }
- }
- public class cat : animal // inheritance
- {
- public cat()
- {
- Name = "Basbosa";
- }
- public new void sound() // hide the base method
- {
- 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 base class
- cat obj = new cat();
- obj.sound();
- dog obj2 = new dog();
- obj2.sound();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement