1 / 8

CSH 2009-2010

CSH 2009-2010. A Short Review of Creating Objects in Memory using Test Classes. What is a Test Class?. Class used only for the purpose of testing out the methods of another class. Has only one method – main() Like World.myfirstmethod() in Alice. Test class for BankAccount class.

chaman
Download Presentation

CSH 2009-2010

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSH 2009-2010 A Short Review of Creating Objects in Memory using Test Classes

  2. What is a Test Class? • Class used only for the purpose of testing out the methods of another class. • Has only one method – main() • Like World.myfirstmethod() in Alice

  3. Test class for BankAccount class public class TestBankAccount { public static void main() { //create objects and test them here } }

  4. 4 parts to creating and testing objects: Part one Declare (announce) an object reference variable BankAccount JohnsAccount;

  5. 4 steps to creating and testing objects: Part two Create an object by calling one of the constructors using the new command. The constructor puts starting values into the private fields of the new object. new BankAccount(500.0);

  6. 4 parts to creating and testing objects: Part three Store the memory address of the object created by the constructor in the object reference variable from step one. JohnsAccount = new BankAccount(500.0);

  7. 4 parts to creating and testing objects: Part four Use the object reference variable to call methods on the object JohnsAccount.getBalance();

  8. JohnsBankAccount @197bb7 Memory public void getBalance() private double balance 500.0

More Related