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()); } }
3 odpowiedzi
+ 3
you can Check it in playground....
+ 2
Put it into Code and see for yourself. 😉
+ 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.