TopAnnouncements about labDefining new classes

Defining new classes

We looked at the ClassyBasketball example and discussed how to implement it by defining a new BBall class which encapsulates all the things that we want the ball to be and to do in ClassyBasketball. Click to see the applet and code: ClassyBasketball

We then discussed, more generally, how to define a new class.

The structure of a class is as follows:

    public class Name
    {
        constant and instance variable declarations

        constructor definition(s)
       
        method definitions
    }

When we define a new class:

Notice the differences between the move and contains method in BBall. Also notice how moveTo cleverly uses the move method of the class via writing this.move(...,...).


TopAnnouncements about labDefining new classes