0

What will be the output ???

class Shape { public int area() { return 0; } } class Square extends Shape { public int area() { return 5; } } class Rectangle extends Shape { public int area() { return 9; } } public class box { public static void main(String[] args) { Shape obj = new Square(); Shape obj0 = new Rectangle(); obj = obj0; System.out.println(obj.area()); } }

21st Jul 2022, 4:37 PM
RAGHUNATHA REDDY CHAVVA
RAGHUNATHA REDDY CHAVVA - avatar
3 Answers
+ 3
you can Check it in playground....
21st Jul 2022, 4:39 PM
Jayakrishna 🇼🇳
+ 2
Put it into Code and see for yourself. 😉
21st Jul 2022, 4:40 PM
Felix Alcor
Felix Alcor - avatar
+ 1
CHAVVA RAGHUNATHA REDDY You have assigned object of Rectangle to object of Square. It happened because both class are inheriting same class Shape. So area of rectangle will be area of square.
21st Jul 2022, 5:07 PM
AÍąJ
AÍąJ - avatar