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



Your comments will be displayed only after manual approval.