We use the 'new' keyword in

  1. Overriding

  2. Overloading

  3. Shadowing

  4. Method Hiding

  5. Both c and d


Correct Option: E

AI Explanation

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.

Find more quizzes: