-
What is the outcome of below code SquareExample class?
class Shape
{
public int area()
{
return 2;
}
}
class Square extends Shape
{
public int area()
{
return 7;
}
}
public class SquareExample
{
public static void main(String[] args)
{
Shape obj = new Shape();
Square obj0 = new Square();
obj0 = obj;
System.out.println(obj0.area());
}
}
-
- Compilation Error
- Runtime Error
- Default Value
- 7
- None of these
Correct Option: A
Compilation Error
SquareExample.java:23: error: incompatible types: Shape cannot be converted to Square
obj0 = obj;
^
1 error