-
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);
}
}
-
- 25 1
- 1 25
- 0 5
- 5 0
- 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.