-
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);
}
}
-
- 0 4 16
- 4 0 16
- 16 0 4
- Compilation Error
- Runtime Error
Correct Option: A
0 4 16