Home » JAVA Programming » Inheritance » Question
  1. 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());
    }
    }
    1. 0
    2. Compilation Error
    3. Runtime Error
    4. Default value
    5. 5
Correct Option: E

Child object can be assigned to parent variable without change in behaviour.



Your comments will be displayed only after manual approval.