filmov
tv
Java Polymorphism Trick You Didn't Expect! 🤯 | Java Interview Question #shorts #interview #java

Показать описание
Confused why this prints 10 instead of 20 in Java? Let's break it down!
That’s because Java only uses polymorphism for methods, not for variables (fields). Even though obj is an instance of Child, it’s declared as a Parent, so Java accesses the value field from the Parent class.
This is called field hiding, not overriding. Java decides which variable to access based on the reference type — not the actual object type.
It's a common trap in coding interviews and real projects!
👍 Follow @CodeSnap-UR for more Java tips, tricks, and interview-ready explanations!
That’s because Java only uses polymorphism for methods, not for variables (fields). Even though obj is an instance of Child, it’s declared as a Parent, so Java accesses the value field from the Parent class.
This is called field hiding, not overriding. Java decides which variable to access based on the reference type — not the actual object type.
It's a common trap in coding interviews and real projects!
👍 Follow @CodeSnap-UR for more Java tips, tricks, and interview-ready explanations!
Java Polymorphism Trick You Didn't Expect! 🤯 | Java Interview Question #shorts #interview #java...
Java 9d: Objects : Polymorphism
Java Interview Short 8 - why abstract class is used - No Abstract method use-case | #javainterview
Top 5 Terrible Java Coding Techniques You Need to Be Using Right Now
What is Runtime Polymorphism in Java? And Why Should You Care? | Java Tutorial
What kind of method can you override? - Cracking the Java Coding Interview
Java Runtime Polymorphism: Tips and Tricks | What is Runtime Polymorphism in Java? | Java Tutorial
The many shapes of Polymorphism by Luca Molteni
Why Java Is So Hard To Learn
Method Overloading Tricky Java Interview Question
Abstract Classes and Methods in Java Explained in 7 Minutes
Adventures in Parametric Polymorphism
Polymorphism in Java : Explained Simply for Beginners and Experts | Dynamic Behavior
Learn Java Object-Oriented Programming (with actual code)
Abstarct class contain constructor but interface doen't why
Experienced Java interview question | #2
Memory Trick for OOP Principles: Learn 'A PIE' for Java 💡 | OOP Explained
Quick Guide to Polymorphism in Object-Oriented Programming
Exception Handling in Java Tutorial
Why we can't instantiate abstract class in java?
Object Oriented Programming is a Dirty Rotten Low Down Trick: A Look at How C++ Works
Achieve Polymorphism in JAVA by Inheriting Attributes and Methods from Another Class 🥇
OOPS concepts explained in 50 seconds |
Day 33: Java Coding for Beginners | Polymorphism Explained | OOPs Concept #shorts
Комментарии