-
What is the outcome of below Square_Shape_Example class?
class Shape
{
public int area()
{
return 1;
}
}
class Square extends Shape
{
public int area()
{
return 5;
}
}
public class Square_Shape_Example
{
public static void main(String[] args)
{
Shape obj = new Shape();
Square square = new Square();
obj = square;
System.out.println(obj.area());
}
}
-
- 0
- Compilation Error
- Runtime Error
- Default value
- 5
Correct Option: E
Child object can be assigned to parent variable without change in behaviour.