Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ParentClass
- {
- public int methodOne()
- {
- return methodTwo();
- }
- virtual public int methodTwo()
- {
- return 1;
- }
- }
- class ChildClass : ParentClass
- {
- override public int methodTwo()
- {
- return 2;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var a = new ChildClass();
- Console.WriteLine("a.methodOne(): " + a.methodOne());
- Console.WriteLine("a.methodTwo(): " + a.methodTwo());
- Console.WriteLine("((ParentClass)a).methodTwo(): "
- + ((ParentClass)a).methodTwo());
- Console.ReadLine();
- }
- }
- class ChildClass : ParentClass
- {
- new public int methodTwo() // bad, do not do
- {
- return 2;
- }
- }
Add Comment
Please, Sign In to add comment