Java Reference
In-Depth Information
conditional A conditional statement takes one of two possible actions based upon the result
of a test.
boolean expression Boolean expressions have only two possible values: true and false. They are
commonly found controlling the choice between the two paths through a conditional statement.
local variable A local variable is a variable declared and used within a single method. Its
scope and lifetime are limited to that of the method.
The following exercises are designed to help you experiment with the concepts of Java that
we have discussed in this chapter. You will create your own classes that contain elements
such as fields, constructors, methods, assignment statements, and conditional statements.
Exercise 2.83 Below is the outline for a Book class, which can be found in the book-exercise
project. The outline already defines two fields and a constructor to initialize the fields. In this and
the next few exercises, you will add features to the class outline.
Add two accessor methods to the class— getAuthor and getTitle —that return the
author and title fields as their respective results. Test your class by creating some
instances and calling the methods.
* A class that maintains information on a book.
* This might form part of a larger application such
* as a library system, for instance.
* @author (Insert your name here.)
* @version (Insert today's date here.)
public class Book
// The fields.
private String author;
private String title;
* Set the author and title fields when this object
* is constructed.
public Book(String bookAuthor, String bookTitle)
author = bookAuthor;
title = bookTitle;
// Add the methods here...
Search WWH ::

Custom Search