Question: What is the output of the driver code? public class Gambler { private int money; public Gambler ( int m ) { money = m;

What is the output of the driver code?
public class Gambler {
private int money;
public Gambler(int m){ money = m; }
public int currentMoney(){ return money; }
public void addMoney(int m){ money += m; }
public void work(){ money +=100; }
public void play(){ money /=2; }
public void liveAnotherDay(){ work(); play(); }
public String toString(){ return money+""; }
}// end of class Gambler
public class CompulsiveGambler extends Gambler {
public CompulsiveGambler(int m){ super(m); }
public void work(){/* do nothing */}
public void play(){
while (currentMoney()>1)
super.play();
}// end of play
}// end of class CompulsiveGambler
// in client code
Gambler x = new CompulsiveGambler(100);
x.liveAnotherDay();
System.out.println(x);

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!