Back to articles
UNIVERSAL METHOD OVERRIDING TEMPLATE
NewsCareer

UNIVERSAL METHOD OVERRIDING TEMPLATE

via Dev.toEr. Bhupendra

Bhupendra, all these questions are actually based on one core rule of Method Overriding . Instead of memorizing answers separately, use one universal template . ⭐ UNIVERSAL METHOD OVERRIDING TEMPLATE Start every answer like this in interview: Method overriding works on runtime polymorphism where a child class provides its own implementation of a parent class method. For overriding to happen, some rules must be followed such as method visibility, inheritance, and method signature compatibility. Based on this rule, the answer is: Then give Yes / No + Reason . 🔥 MASTER OVERRIDING RULES (Remember this) 1. Method must be inherited 2. Cannot reduce visibility 3. Static methods cannot override 4. Final methods cannot override 5. Private methods cannot override 6. Return type must be same or covariant If you know these 6 rules , all questions are solved. APPLY TEMPLATE TO YOUR QUESTIONS 1️⃣ Can we override private method? Answer Method overriding works when a child class inherits a method from

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles