Constructors with Multiple Parameters

Sometimes you’ll want to initialize objects with multiple data items. In Exercise B.11, we ask you to store the course name and the instructor’s name in a GradeBook object. In this case, the GradeBook’s constructor would be modified to receive two Strings, as in

public GradeBook( String courseName, String instructorName )

and you’d call the GradeBook constructor as follows:

GradeBook gradeBook = new GradeBook(   "CS101 Introduction to Java Programming", "Sue Green" );

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.