Computer Science, asked by josephbaiju, 9 months ago

What will be the output of the following : char m = ‘A’; int p =15; int n=m+p; System.out.println(“Answer:”+n);

Answers

Answered by sksinha213
1

Answer:15

Explanation:

Answer:

10 66 1 mark if correct reason 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 3 marks

- method origin2() is invoked and parameter p starts

referring to object referred by q. Through use of p

instance variables of 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. 2 mark

Similar questions