public class worksheet3_1 { public static void main(String[] arg) { ShadowingExample example = new ShadowingExample(); example.x = 99; example.sampleMethod(); } } class ShadowingExample { int x; public void sampleMethod() { int x = 0; System.out.println("the value of local variable x = " + ………………………………………………); System.out.println("the value of instance variable x = " + …………………………………………); } } what should be written in the second print statement so that the output is: the value of instance variable x = 99 what should be written in the first print statement so that the output is: the value of local variable x = 0 options are: samplemethod.x this.x shadowingexample.x x
public class worksheet3_1 {
public static void main(String[] arg) {
ShadowingExample example = new ShadowingExample();
example.x = 99;
example.sampleMethod();
}
}
class ShadowingExample {
int x;
public void sampleMethod() {
int x = 0;
System.out.println("the value of local variable x = " + ………………………………………………);
System.out.println("the value of instance variable x = " + …………………………………………);
}
}
what should be written in the second print statement so that the output is: the value of instance variable x = 99 what should be written in the first print statement so that the output is: the value of local variable x = 0 options are: samplemethod.x this.x shadowingexample.x x |
Answer 1 Question 1 |
Step by step
Solved in 4 steps with 1 images