-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: RedSunBeer
Message 2 in Discussion

 using System;
 class A
{
        /*The method 'F' being virtual depends upon some other class method to 
implement it. */         public virtual void F() { 
        Console.WriteLine("A.F"); 
    }
}  
class B: A  //class B inherits A
{     ///method 'F' of class B overrides the method 'F' of class A        ///This 
means the code in method 'F' of class A will not be executed
    public override void F()       { 
        Console.WriteLine("B.F"); 
    }
} 
class C: B //class C inherits B
{
     ///method 'F' of class C overrides the method 'F' of class B        ///This means 
the code in method 'F' of class B will not be executed
    new public virtual void F() { 
        Console.WriteLine("C.F"); 
    }
}
class D: C //class D inherits C
{
     ///method 'F' of class D overrides the method 'F' of class C        ///This means 
the code in method 'F' of class C will not be executed
    public override void F() { 
        Console.WriteLine("D.F"); 
    }
}
class Test
{     //the main method is the entry point for executing this class.      //It is 
always static. Static means you cannot create an new instance of it.
    static void Main()     {
        D d = new D();  //creates an object 'd' of class type 'D'
        A a = d;  //declare a variable 'a'  of class type 'A' and assign object 'd' to 
it. this is possible because class D inherits class A. 
        B b = d;  //declare a variable 'b' of class type 'B' and assign object 'd' to 
it         C c = d;  //declare a variable 'c'  of class type 'C' and assign object 'd' 
to it 
        a.F(); //this is a virtual method so it will be executed by the class method 
that implements it, in this case B.F()
         b.F(); //this is a concrete class method and so it will execute.
        c.F(); //similar to a.F()
        d.F(); //similar to b.F()
    }
}
the output:
    B.F
    B.F
    D.F
    D.F
   ps: I could be wrong you know OOPs :)

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to