please tell me why the code print out that in the console Q1. Consider the follo
ID: 3793178 • Letter: P
Question
please tell me why the code print out that in the console
Q1. Consider the following code public class ABC private static int count private int x; public ABC (int i) public void incrementCount Count public void print X System out.println ("Value of x x) i public static void printCount System. out.println ("Value of count count) public static void main (String C] args) ABC demo new ABC (5) ABC Obj 1 new ABC (2) ABC Obj 2 new ABC (5) Obj 1. printX O; Obj 1. increment Count demo. increment Count obj1. Count o; print, Obj2.print CountExplanation / Answer
First of all static means it declears only single time .
Here is step by step execution that how it prints?
public static void main(String []args){
ABC demo = new ABC(5);
ABC Obj1 = new ABC(2);
ABC Obj2 = new ABC(5);
Obj1.printX(); //print x value of Obj1 output is 2
Obj1.incrementCount(); // increments the count to 1
demo.incrementCount(); // increments the count to 2
Obj1.printCount(); // prints the count output is 2
Obj2.printCount(); // prints the count output is 2
Obj2.printX(); // print the value of x in Obj2 . output is 5
Obj1.incrementCount(); // increments the count to 3
Obj1.printX(); // print the value of x in Obj1 . output is 2
Obj1.printCount(); // prints the count output is 3
Obj2.printCount(); // prints the count output is 3
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.