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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started