-
What is the outcome of below code box class?
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());
}
}
-
- Compilation Error
- Runtime Error
- Default value
- 9
- None of these
Correct Option: D
The method of the child class object is accessed. When we reassign objects, the methods of the latest assigned object are accessed.