printing reference to an object – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2015-03F #JAVA#4261    siteicon   siteicon  

Problem Statement - printing reference to an object

(i) What will the code print?

int arr[] = new int [5];
System.out.println(arr);

(i) 0 (ii) value stored in arr[0] (iii) 0000 (iv) garbage value

(ii) Name the keyword which is used to resolve the conflict between method parameter and instance variables/fields

Solution

TC++ #4261

(i) The output would be a garbage value.

(ii) this keyword.

Notes

(i)

(ii)  

Example showing practical use of this keyword.

class Test {
int a=10;
void try(int a) {
System.out.println(a); //This will print value  passed to try method
System.out.println(this.a); //This will print 10 the class/instance variable
}
}


Share

sunmitra| Created: 5-Apr-2018 | Updated: 16-Apr-2019|ICSE2015









Back