229k views
5 votes
Determine the output of the following code. Note: assume that Point class is provided and has 2 public variables x and y: public class Point { public int X; public int Y; } public class ValueVsReference { public static void main(String[] args) { int y = 33; incrementInteger(y); System.out.print(y); Point p = new Point(); p.X = 33; p.Y = 33; movePoint(p, 1, 1); System.out.print(p.X + " " + p.Y); } public static void incrementInteger(int inValue) { inValue++; } public static void movePoint(Point p, int deltaX, int deltaY) { p.X += deltaX; p.Y += deltaY; } }

User TheNickyYo
by
4.6k points

2 Answers

3 votes

Answer:

output :

34

34 34

Step-by-step explanation:

output :

34

34 34

Having that the variable y is passed as pass by value to method increment Integer, this is even as y value incremented it doesn't effect actual y value.

Hence, having seen this, y will not be incremented after the execution of method and to move Point method we passed point object

and we accessed X,Y through point object that's why they incremented.

User Andile
by
4.9k points
2 votes

Answer:

Check the explanation

Step-by-step explanation:

There are 4 errors.

public keyword

string is not any datatype in c. It would be char.

undeclared identifier for both this.id and this.name

Determine the output:-

It would be 33 34 34.

33 is their because the value will be decremented afterwards as we are using the postfix increment operator and when we are calling movePoint(p,1,1) we are increasing 33 to 34. And we are using System.out.print which will print the values in one line.

So it prints 33 34 34

User Amitchhajer
by
4.8k points