[d] What will be the output of following code :
int a = 10;
int b = 15:
while (++a< --b)
System.out.println (b);
System.out.println (a);
Answers
Answer:
Explanation:
Answer:
10 66 1 mark if the correct reason was given
15 20 1 mark if correct reason given
Reason:
- Initially an object is created which is referred by q
and has instance variables p=10 and q=66.
- When method origin1() is invoked the parameter p
starts referring to the object referred by q. However,
p=new point(0,0) creates a new object (instance
variables p=0, q=0), and p starts referring to the new
object. Since, p is a local variable, any change to p is
not visible outside the method. Therefore, instance
variables of q do not change
- q.printpoint(), therefore, prints values of instance
variables of q which are 10 and 66
- method origin2() is invoked and parameter p starts
referring to the object referred by q. Through the use of p
instance variables of the object referred by q, are
modified. The change is done in the object itself.
Hence, instance variables of the object change to p=15
and q=20.
- q.printpoint() prints values of instance variables of q
which are now 15 and 20.
Answer:
14
11
13
12
Explanation:
In while loop the condition will be checked first,
First Check:
++a= 11
--b=14
11<14 and so it will display:
14
11
2nd Check:
++a= 12
--b=13
12<13 So it will print:
13
12
3rd Check:
++a= 13
--b=12
13<12 is false, So while condition ends