What is the result? Given the code fragment: What is the result? Given the code fragment: What is the result? A. 10 : 10 B. 5 : 5 C. 5 : 10 D. Compilation fails Show Hint ← Previous question Next question →
renko Answer: A package q082; public class Test { static int count = 0; int i = 0; public void changeCount() { while (i < 5) { i++; count++; } } public static void main(String[] args) { Test check1 = new Test(); Test check2 = new Test(); check1.changeCount(); check2.changeCount(); System.out.println(check1.count +" : "+ check2.count); } } /*Output: 10 : 10 */ Reply
Answer: A
package q082;
public class Test {
static int count = 0;
int i = 0;
public void changeCount() {
while (i < 5) {
i++;
count++;
}
}
public static void main(String[] args) {
Test check1 = new Test();
Test check2 = new Test();
check1.changeCount();
check2.changeCount();
System.out.println(check1.count +" : "+ check2.count);
}
}
/*Output:
10 : 10
*/