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.
The interest obtained on Rs. (2p + 600) at 18% p.a. for 5 years (simple interest) is Rs. (p + 840). Find the ratio (p - 75) :(p + 25)
- Ajay and Vijay jointly invest an amount 'x' in a simple interest scheme for 4 years. Ajay contributes 40% of 'x' at an interest rate of 7% per annum, while...
A certain sum of money at simple interest amounts to Rs 7200 in 3 years and Rs 8000 in 5 years. What is the rate of interest per annum?
Rs. (y-1500) was invested in scheme J on (R-1)% per annum on compound interest. Rs. ‘y’ was invested in scheme K on (R+1)% per annum on simple inter...
A sum of money amounts to Rs. 5600 in 5 years at simple interest. If the principal is Rs. 4000, find the rate of interest per annum.
A certain sum of money invested at a rate of 48% p.a. amounts to Rs. 20736 at the end of 15 months if the rate of interest is compounded 5 monthly. Find...
Rs. (x + 800) is invested at 12% simple interest per annum for 5 years. The interest earned is Rs. (x - 320). If Rs. (x - 400) is...
Simple interest and compound interest (compounded annually) earned on a sum at the end of 2 years at a certain rate of interest p.a. are Rs. 4500 and Rs...
Rs. 13000 invested for 2 years in a scheme offering compound interest (compounded annually) of 15% p.a. gives an interest that is Rs. 10 less than the i...
Shivam invested 24000 at 8% p.a. simple interest for ‘x’ months. If at the end of ‘x’ months, he received a total amount of Rs.27200. What is th...