Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test4 : test2
- {
- public test4 ()
- {
- this.name = "test4";
- }
- public override void DoIt()
- {
- // call the base methods DoIt first
- base.DoIt();
- // then do this
- System.Console.WriteLine("test 4 derived" );
- }
- }
- public class test3 : test2
- {
- public test3 ()
- {
- this.name = "test3";
- }
- // override means it has overriden a base class virtual
- // method
- public override void DoIt()
- {
- System.Console.WriteLine("test3 derived" );
- }
- }
- public class test2
- {
- public string name { get; protected set; }
- public test2 ()
- {
- this.name = "test2";
- }
- // virtual means that this method can be overriden
- public virtual void DoIt()
- {
- System.Console.WriteLine("test2 base" );
- }
- }
- public class test
- {
- static void Main ()
- {
- test3 t3 = new test3();
- test4 t4 = new test4();
- System.Console.WriteLine(t3.name);
- t3.DoIt();
- System.Console.WriteLine(t4.name);
- t4.DoIt();
- }
- }
Add Comment
Please, Sign In to add comment