B.2 Declaring a Class with a Method and Instantiating an Object of a Class

In this section, you’ll create a new class, then use it to create an object. We begin by delcaring classes GradeBook (Fig. B.1) and GradeBookTest (Fig. B.2). Class GradeBook (declared in the file GradeBook.java) will be used to display a message on the screen (Fig. B.2) welcoming the instructor to the grade book application. Class GradeBookTest (declared in the file GradeBookTest.java) is an application class in which the main method will create and use an object of class GradeBook. Each class declaration that begins with keyword public must be stored in a file having the same name as the class and ending with the .java file-name extension. Thus, classes GradeBook and ...

Get Android How to Program, 3/e 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.