Exemplo n.º 1
0
        public static void Main1()
        {
            //** MOST IMPORTANT NOTE: ** All static constructor get called first according to above hierarchy then it calls to normal constructors
            // Also static constructors can't be called explictly and we can't control the calling of static constructors

            /* It should always be remembered that constructor creation goes Child to Parent constructor for static constructors
             * and Parent to Child constructors for normal class constructors
             */
            /* We can't write any access specifier with static constructor. e.g.
             *
             * public static StaticClass(){}     //It will give a compilation error that "access modifiers are not allowed on static constructors"
             */
            /* We can't create overloaded static constructors. i.e.
             *
             * static StaticClass(string str)    //It's a compile time error, i.e. "Static constructor must be parameterless"
             */

            //Parent parent = new Parent();       // It'll call Parent static constructor then default Parent class constructor
            //Console.WriteLine("Parent Class Ends Here\n\n");

            //Child child = new Child();            // It'll call child static then Parent static constructor then Parent default constructor then child class default constructor
            //Parent parentChild = new Child();     // Constructor calling order will be similar to above style
            //Console.WriteLine("Child Class Ends Here\n\n");

            //ChildOfChild childOfChild = new ChildOfChild();     //  constructor Calling order will be ChildOfChild then Child then Parent class static constructors first
            Child parentOfChildOfChild = new ChildOfChild();      //  afterwards Parent then Child then ChildOfChild normal constructors

            //Parent parentChildOfChild = new ChildOfChild();     //  Constructor calling order for this and above 2 lines would be same
            //Console.WriteLine("Child Class Ends Here\n\n");

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public static void Main1()
        {
            //var obj = new { city = "New York" };
            //Console.WriteLine(obj.city); // New York
            //dynamic obj1 = new { city = "New York 2" };
            //Console.WriteLine(obj1.city); // New York 2
            //Console.WriteLine(20 + 45 + "A"); // 65A
            //Console.WriteLine("A" + 20 + 45); // A2045
            //Console.WriteLine(20 + "A" + 45); // 20A45
            //int hoogtePlaatjes = 900;
            //int breedtePlaatjes = 600;
            //double verHs = (hoogtePlaatjes / breedtePlaatjes);


            //Parent oParent = new Parent();
            //Parent oParentChild = new Child();
            //Child oChild = new Child();
            //Child oChildP = new Parent();  //----------Its a compile time errer
            //Child oChildParent = (Child)new Parent();  //----------Its a run time errer

            //Parent objParent = new Parent();
            //Console.WriteLine("Parent: " + objParent.GetTypeWithoutOverRiding());
            //Console.WriteLine("Parent: " + objParent.GetTypeWithOverRiding());
            //Console.WriteLine("Parent: " + objParent.StopOverRiding());
            //Console.WriteLine("Parent Class Ends Here\n");

            //Child objChild = new Child();
            //Console.WriteLine("Child: " + objChild.GetTypeWithoutOverRiding());
            //Console.WriteLine("Child: " + objChild.GetTypeWithOverRiding());
            //Console.WriteLine("Child: " + objChild.StopOverRiding());
            //Console.WriteLine("Child Class Ends Here\n");

            Parent objParentChild = new Child();                     // It will call both level constructers i.e. Parent & Child class constructors

            //Parent objParentChild = new Child("");
            Console.WriteLine("Parent-Child: " + objParentChild.GetTypeWithoutOverRiding());    // this one will call to Parent class method GetTypeWithoutOverRiding()
            Console.WriteLine("Parent-Child: " + objParentChild.GetTypeWithOverRiding());       // this one will call to Child class method GetTypeWithOverRiding()
            Console.WriteLine("Parent-Child: " + objParentChild.StopOverRiding());
            //Console.WriteLine("Parent-Child: " + objParentChild.OnlyChildMethod());           // this one will give compilation method that class doesn't contain any definition for OnlyChildMethod
            Console.WriteLine("Parent-Child Class Ends Here\n");

            //Parent objParentChildofChild = new ChildOfChild();      // It will call all three level constructers i.e. Parent, Child & then ChildOfChild class constructors
            //Console.WriteLine("Parent-Child: " + objParentChildofChild.GetTypeWithoutOverRiding());    // this one will call to Parent class method GetTypeWithoutOverRiding()
            //Console.WriteLine("Parent-Child: " + objParentChildofChild.GetTypeWithOverRiding());       // this one will call to ChildOfChild class method GetTypeWithOverRiding()
            //Console.WriteLine("Parent-Child: " + objParentChildofChild.StopOverRiding());
            //Console.WriteLine("Parent-ChildofChild Class Ends Here\n");

            ChildOfChild objChildOfChild = new ChildOfChild();      // It will call all three level constructers i.e. Parent, Child & then ChildOfChild class constructors

            //Console.WriteLine("ChildOfChild: " + objChildOfChild.GetTypeWithoutOverRiding());
            //Console.WriteLine("ChildOfChild: " + objChildOfChild.GetTypeWithOverRiding());
            //Console.WriteLine("ChildOfChild: " + objChildOfChild.StopOverRiding());   // this one will call to child class method StopOverRiding()
            //Console.WriteLine("ChildOfChild Class Ends Here");

            Console.ReadKey();
        }