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
Get step-by-step solutions from verified subject matter experts
