We use the 'new' keyword in
-
Overriding
-
Overloading
-
Shadowing
-
Method Hiding
-
Both c and d
The 'new' keyword in C# is used for method hiding, which is also referred to as shadowing. When a derived class method has the same name as a base class method but isn't marked with 'override', using 'new' explicitly indicates you're intentionally hiding the base method. Shadowing and method hiding are the same concept in C# terminology. Overriding requires virtual/override keywords, while overloading refers to having multiple methods with different parameters.
To answer this question, we need to understand the concepts of overriding, overloading, shadowing, and method hiding.
Overriding: Overriding is a concept in object-oriented programming where a subclass provides a specific implementation of a method that is already defined in its superclass. The 'new' keyword is not used in overriding.
Overloading: Overloading is a concept in object-oriented programming where multiple methods can have the same name but different parameters. The 'new' keyword is not used in overloading.
Shadowing: Shadowing is a concept in object-oriented programming where a variable or a method in a subclass has the same name as a variable or method in its superclass. The 'new' keyword can be used to explicitly indicate that the subclass is intentionally shadowing the superclass member.
Method Hiding: Method hiding is a concept in object-oriented programming where a subclass defines a static method with the same name as a static method in its superclass. The 'new' keyword can be used to explicitly indicate that the subclass is intentionally hiding the superclass method.
Based on the above explanations, we can conclude that the 'new' keyword is used in both shadowing and method hiding. Therefore, the correct answer is E) Both C and D.