Question: Java: Consider the code below: public class MyObject { private int myData; public MyObject() { myData = 0; } public MyObject( int n ) {

Java:

Consider the code below:

public class MyObject { private int myData; public MyObject() { myData = 0; } public MyObject( int n ) { myData = n; } public void increment() { myData++; } public int getData() { return myData; } }

public class TestMyObject { public static MyObject aMethod( MyObject obj ) { MyObject result = obj; result.increment(); return result; }

public static void main( String [] args ) { MyObject x = new MyObject( 1 ); MyObject y = new MyObject( 6 ); MyObject z = y; x = aMethod( y ); z = aMethod( x ); } }

What are the data member values for x, y, and z just before the program ends?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!