Question
Examine the following Java-like code:
```java class Parent { String name = "Parent"; public void display() { System.out.println(name); } } class Child extends Parent { String name = "Child"; // No display method override } public class Main { public static void main(String[] args) { Parent p = new Child(); p.display(); } } ``` What will be the output?Solution
This demonstrates variable hiding (not overriding) and method overriding. `Parent p = new Child();` creates a `Child` object but the reference `p` is of type `Parent`. When `p.display()` is called, Java uses dynamic method dispatch (polymorphism) to call the `display()` method of the actual object type, which is `Child`. However, `Child` does not override the `display()` method. Therefore, the `display()` method from the `Parent` class is executed. Inside `Parent.display()`, `name` refers to `Parent.name`, which is "Parent". The `Child`'s `name` variable is a separate, hidden variable.
Discrepancy के लिए सही हिन्दी पारिभाषिक शब्द है
निम्नलिखित में से कौन सा ‘विधान शब्द का शब्दावली में सही...
इस प्रश्न में हिंदी में एक वाक्य दिया गया है। नीचे दिये गय�...
दिए गए प्रत्येक प्रश्न में एक अंग्रेजी का वाक्य दिया �...
INDISPENSABL का हिन्दी अर्थ है ?
निम्नलिखित में से sweat equity का पर्याय नहीं होगा ?
दिए गए प्रत्येक प्रश्न में एक हिंदी का वाक्य दिया गया �...
Value Added Tax is determined using the invoice method.मूल्य संवर्द्धन कर इनवॉयस विधि क�...
A vast blanket of pollution stretching across South Asia is cutting down sunlight by 10 percent over India.
दिए गए वाक्य का उचित हिंदी अनुवाद चुने
In ancient times India h...