Home » JAVA Programming » Interfaces » Question
  1. What is the output of this program?
    interface Calculation 
    {
    int var = 0;
    void calculate(int num);
    }

    class display implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    if (num<2)
    {
    p = var;
    }
    else
    {
    p = num * num;
    }
    }
    }

    public class interfaces_Example
    {

    public static void main(String args[])
    {
    display[] array = new display[4];

    for(int k=0; k<4; k++)
    array[k] = new display();
    array[0].calculate(0);
    array[1].calculate(2);
    array[2].calculate(4);
    System.out.print(array[0].p+" " + array[1].p + " " + array[2].p);
    }
    }
    1. 0 4 16
    2. 4 0 16
    3. 16 0 4
    4. Compilation Error
    5. Runtime Error
Correct Option: A

0 4 16



Your comments will be displayed only after manual approval.