question archive What gets printed by the following code? BiggerMystery m; m = new BiggerMystery(); System
Subject:Computer SciencePrice: Bought3
What gets printed by the following code?
BiggerMystery m;
m = new BiggerMystery();
System.out.println("m has value "+ m.toString() );
You are given following java definitions:
public class Mystery{
protected int val;
protected Thing t;
public Mystery (){
val= 1;
t= new Thing ( this );
}
public void accum ( int x ){
val *= x;
}
public String tostring(){
return Integer.toString(val) ;
}
}
public class BiggerMystery extends Mystery{
public BiggerMystery(){
super();
}
public void accum ( int x ){
super.accum(x);
val += x;
}
}
public class Thing{
private int[][] arr;
private Mystery mystery;
public Thing ( Mystery mystery ){
this.mystery= mystery;
arr=new int[2][3];
for (int i=0;i<arr.length;i++ )
for (int j=0; j< arr[i].length; j++ )
arr[i][j]=(i+1) *j;
doYerThing();
}
private void doYerThing()
{
for (int i= 0; i<arr.length; i++ )
for (int j= 0; j< arr[i].length; j++ )
mystery.accum( arr[i][j]);
}
}