Java Reference
In-Depth Information
Exercise 1.24
Call the
numberOfStudents
method of that class. What does it do?
Exercise 1.25
Look at the signature of the
enrollStudent
method. You will notice that
the type of the expected parameter is
Student
. Make sure you have two or three students
and a
LabClass
object on the object bench, then call the
enrollStudent
method of the
LabClass
object. With the input cursor in the dialog entry field, click on one of the student
objects; this enters the name of the student object into the parameter field of the
enroll-
Student
method (Figure 1.9). Click OK and you have added the student to the
LabClass
.
Add one or more other students as well.
Exercise 1.26
Call the
printList
method of the
LabClass
object. You will see a list of
all the students in that class printed to the BlueJ terminal window (Figure 1.10).
Figure 1.9
Adding a student
to a
LabClass
Figure 1.10
Output of the
LabClass
class
listing
As the exercises show, objects can be passed as parameters to methods of other objects. In
the case where a method expects an object as a parameter, the expected object's class name
is specified as the parameter type in the method signature.
Explore this project a bit more. Try to identify the concepts discussed in the
figures
example in
this context.
Search WWH ::
Custom Search