Home » JAVA Programming » Interfaces » Question
  1. What is the output of this program?
    interface Calculation
    {
    void calculate(int item);
    }
    class display0 implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    p = num * num;
    }
    }

    class display1 implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    p = num / num;
    }
    }

    public class interfaces_Example
    {
    public static void main(String args[])
    {
    display0 object0 = new display0();
    display1 object1 = new display1();
    object0.p = 0;
    object1.p = 0;
    object0.calculate(5);
    object1.calculate(5);
    System.out.print(object0.p + " " + object1.p);
    }
    }
    1. 25 1
    2. 1 25
    3. 0 5
    4. 5 0
    5. None of these
Correct Option: A

class display0 implements the interface calculate by doubling the value of num, where as class display1 implements the interface by dividing num by num, therefore variable p of class display0 stores 25 and variable p of class display1 stores 1.



Your comments will be displayed only after manual approval.