Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 28

Given:

What is the result?

    Correct Answer: C

    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.

Discussion
dya45792Option: C

Antwort C, ist richtig : 5 4 5 6

v323rsOption: C

The correct answer is C, "5 4 5 6"

RoxyFoxyOption: C

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

Stewart125Option: C

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.

mete23Option: C

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); } }

Dolly2901Option: C

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

anmoldev2javaOption: C

c is ans

Andrei_NicolaeOption: C

C is correct

hexadecimal82Option: C

C is correct

hexadecimal82Option: D

C is the correct answer. Changing a static variable value changes it in all instances of the class

SSJ5Option: C

Correct answer is C

AhmadTechieOption: C

Answer is C => as i is static variable it always hold updated value that is shared by all instances

Vicky_65Option: C

The right one is C

SamAruOption: C

Agreed, Option C is correct!