-
What is the outcome of below code Rectangle_Example class?
class Shape
{
public int area()
{
return 2;
}
}
class Rectangle extends Shape
{
public int area()
{
return 6;
}
}
public class Rectangle_Example
{
public static void main(String[] args)
{
Shape obj = new Shape();
Rectangle obj0 = new Rectangle();
obj = obj0;
System.out.println(obj.area());
}
}
-
- 6
- Runtime Error
- Default Value
- Compilation Error
- None of these
Correct Option: A
Child object can be assigned to parent variable without change in behaviour.