Tuesday, March 25, 2014

Java Class problems 4 and 12

Problem 4

 public void swapHardDrive(Computer otherComputer)
 {
  String temp;
  temp = this.hardDrive;
  this.hardDrive = otherComputer.hardDrive;
  otherComputer.hardDrive = temp;
 }

Problem 12

Things in bold are output

  1. Contructore without parameter is called
  2. It calls the constructor with an int parameter of 20
  3. 10
  4. 20
  5. Sets private x value to 30
  6. 30
  7. Display without an argument is called
  8. Calls display with an argument set at 50
  9. Adds 10 to it so now its 60
  10. 60
  11. Prints the old x value since non objects are passed by value.
  12. 50

No comments:

Post a Comment