Example #1
0
        //Main-----------------------------------------------------------------------------
        static void Main(string[] args)
        {
            //Inheritance and Polymorphism
            //Instantiate derived class and access its inherited public method
            derivedClass d = new derivedClass(7, "Smith");

            Console.WriteLine(d.Legs); //returns 4
            d.Bark();                  //returns Woof
            d.Speak();
            Console.WriteLine(derivedClass.Number);
            //protected members of base class
            d.SayName(); //Works because derived class SayName method has access to base class' field/var
            //d.LastName = "Jones"; //error, due to "protected" protection level in base class

            //Polymorphism
            Shape c = new Circle();

            c.Draw(); //outputs circle
            Shape r = new Rectangle();

            r.Draw(); //outputs rectangle

            //Abstract class
            abstractClass v = new abstractCircle();

            v.Draw(); //circle

            //Interface
            IShape z = new interfaceCircle();

            z.Draw(); //Outputs circle drawing
            ISquash y = new interfaceCircle();

            y.Squash(); //Outputs about squashing

            //Namespaces
            System.Console.WriteLine("Hello"); //Here, "System" would be required if "using System;" was not called at the start of the file.
        }