Question: [Java] Please help me to figure out why the code below returns the such output ( why t.x: 22 but t.y: 33) ------------------------------------------------------------------------------------------------------------------------------------------------ public class

[Java] Please help me to figure out why the code below returns the such output ( why t.x: 22 but t.y: 33)

------------------------------------------------------------------------------------------------------------------------------------------------

public class Test

{

static int x = 11;

private int y = 33;

public void method1(int x)

{

Test t = new Test();

this.x = 22;

y = 44;

System.out.println("Test.x: " + Test.x);

System.out.println("t.x: " + t.x);

System.out.println("t.y: " + t.y);

System.out.println("y: " + y);

}

public static void main(String args[])

{

Test t = new Test();

t.method1(5);

}

}

-----------------------------------------------------------------------

output

Test.x: 22 t.x: 22 t.y: 33 y: 44

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!