what is the output of the below program when you run MyTest?
public class GemObjects{
private int score;
public GemObjects(int score) {
super();
this.score = score;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
public class MyTest {
public static void main(String[] args) {
GemObjects[] arrOne = new GemObjects[] { new GemObjects(10),
new GemObjects(20), new GemObjects(30) };
GemObjects[] arrTwo = arrOne.clone();
System.out.println("arrOne[2].getScore() = "+arrOne[2].getScore());
System.out.println("arrTwo[2].getScore() = "+arrTwo[2].getScore());
arrTwo[2].setScore(222); //changedonly arrTwo
System.out.println("arrOne[2].getScore() = "+arrOne[2].getScore());
System.out.println("arrTwo[2].getScore() = "+arrTwo[2].getScore());
}
}
what is the output of the below program when you run MyTest?
public class MyTest {
public static void main(String[] args) {
int[] arrOne = new int[] { 10, 20, 30 };
int[] arrTwo = arrOne.clone();
System.out.println("arrOne[2] = "+arrOne[2]);
System.out.println("arrTwo[2]() = "+arrTwo[2]);
arrOne[2]=222; //changedonly arrTwo
System.out.println("arrOne[2 = "+arrOne[2]);
System.out.println("arrTwo[2 = "+arrTwo[2]);
}
}
No comments:
Post a Comment