Computer Science 1
Top Lectures Assignments Noticeboard

Defining Classes, Part III

Implementing methods and testing

State and behavior

  • If we are modeling a real estate company, it is likely that there would be more than one house.
  • Each house would share the same methods but have different instance variables
  • class TaplinRealEstate {
      public static void main (String [] args) {
        House house1 = new House ();
        House house2 = new House ();
        house1.setPrice ("$100000");
        house1.setLocation ("Monaco estates");
        house1.setStyle ("Ranch");
        house2.setPrice ("$150000");
        house2.setLocation ("Clemson");
        house2.setStyle ("Bungalow");
        System.out.println (house1.describe ());
        System.out.println (house2.describe ());
      }
    }

    Java stuff

    Declaration order

    The return statement

    Access control: public vs. private

    Variables and lifetimes

    A default identifier: this


    Last modified: 2/14/99