Question
What is the output of this program? interface calculate { void cal(int item); }
What is the output of this program?
interface calculate {
void cal(int item);
}
class displayA implements calculate {
public int x;
public void cal(int item) {
x = item * item;
}
}
class displayB implements calculate {
public int x;
public void cal(int item) {
x = item / item;
}
}
class interfaces {
public static void main(String args[]) {
calculate arr1 = new displayA();
calculate arr2 = new displayB();
arr1.x = 0;
arr2.x = 0;
arr1.cal(4);
arr2.cal(4);
System.out.print(arr1.x + " " + arr2.x);
}
}
What is the output of this program?
interface calculate {
void cal(int item);
}
class displayA implements calculate {
int x;
public void cal(int item) {
x = item * item;
}
}
class displayB implements calculate {
int x;
public void cal(int item) {
x = item / item;
}
}
class interfaces {
public static void main(String args[]) {
displayA arr1 = new displayA;
displayB arr2 = new displayB;
arr1.x = 0;
arr2.x = 0;
arr1.cal(2);
arr2.cal(2);
System.out.print(arr1.x + " " + arr2.x);
}
}
Step by Step Solution
3.45 Rating (168 Votes )
There are 3 Steps involved in it
Step: 1
The output of the program will be 16 1 Explanation arr...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started