Given:
What is the result?
Given:
What is the result?
In the given code, the variable 'i' is declared as a static variable, which means it is shared among all instances of the class 'X'. There are two instances of the class 'X' created, namely x1 and x2. When x1.i is set to 3, the static variable 'i' for all instances of the class is set to 3. When x2.i is set to 5, the static variable is updated to 5 for all instances, including x1. The variable 'j' is an instance variable, so x1.j only affects the j for the x1 instance, which is set to 4, and x2.j only affects the j for the x2 instance, which is set to 6. Therefore, the output of the code will be 5 4 5 6.
Antwort C, ist richtig : 5 4 5 6
The correct answer is C, "5 4 5 6"
X x1 = new X(); X x2 = new X(); x1.i = 3; // i is static (class variable), i = 3 x1.j = 4; // j is an instance variable, so for x1, j is 4 x2.i = 5; // i is updated from 3 to 5; x2.j = 6; // j is an instance variable, so for x2 j is 6
Option C is correct. Reason is because variable i is declared static so when; x2.i = 5 is called, all X objects i values contain the new assigned value.
The correct answer is C public class X { static int i; int j; public static void main(String[] args) { X x1 = new X(); X x2 = new X(); x1.i = 3; x1.j = 4; x2.i = 5; x2.j = 6; System.out.println(x1.i + " " + x1.j + " " + x2.i + " " + x2.j); } }
static variable is class level variable and it is shared to all objects of that class. and whenever its value gets updated it will update to all objects. so correct ans is 5 4 5 6
c is ans
C is correct
C is correct
C is the correct answer. Changing a static variable value changes it in all instances of the class
Correct answer is C
Answer is C => as i is static variable it always hold updated value that is shared by all instances
The right one is C
Agreed, Option C is correct!