CS51 - Fall 2009 - Lecture 7

  • book problems: casting, == and .equals

  • examples of defining and using classes
  • ClassyBasketball
  • Class contains:
             public class NameOfClass {
                  // constants
    
                  // instance variables
    
                  // constructor(s)
    
                  // method(s)
             }
          
  • thinking at 2 levels: what would someone using the class want to do with it? how do you implement that functionality?
  • instance variables
  • keeps track of the state of an object
  • can be used in multiple methods
  • constructors
  • what does a new object "look" like?
  • at a minimum should initialize the instance variables.
  • parameters as a way of passing information
  • formal parameters in constructor/method declarations
  • actual parameters are passed in when that constructor/method is invoked.
  • methods
  • what can objects of this class do?
  • TShirt class, used in two ways.
  • DragAShirt
  • Drag2Shirts
  • use of keyword this

  • Lab 3:
  • Description: <html> <pdf>