These are set of codes which I wrote. Some are overloading, some are overriding and some are simlpe hiding.
I have clasified them. Are they correct ?
Categories : Overloading, Overriding, Hiding
1. FIRST CODE - Creating an instance of Base class in the subclass. Which cateory does this fall in ? 2. SECOND CODE - Is this Overriding ? Code does not compile. Method "methodInBase" has different return type in subclass as compared to that of the Base class. 3. THIRD CODE - 4. FOURTH CODE - This is Overriding 5. FIFTH CODE - This is Overriding as well 6. SIXTH CODE - This will not compile because sublass variable cannot reference an instance of Base class.
1. FIRST CODE - overloading 2. SECOND CODE - This is not a valid overriding or overloading. That is the reason for compilation error. 3. THIRD CODE - same as above 4. FOURTH CODE - This is Overriding. 5. FIFTH CODE - This is Overriding. 6. SIXTH CODE - This is also Overriding. But, compilation error because base class object can't be assigned to a subclass reference(class2 c2 = new class2Base() . Hope this helps.