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.
Which of the following terms is not associated with marine fish classification?
Microspores that are found directly on microsporangia and are not covered, are classified in which division?
Slate is metamorphosed:
Sponging type of mouth parts are found in which insect?
The Downey mildew of Bajra is caused by
Maize is generally not grown in
Ideal gas equation is:
Thalamus of hypogynous ovary is
Which of the following is/are an imperfect market?
How many calvin cycles are required to produce one molecule of glucose?