[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Back to Classes and Objects. On to Even More Classes and Objects.
Held Monday, September 6, 1999
Overview
Today, we will continue our investigation of classes by considering two other aspects of classes: fields and constructors.
Contents
Handouts
Summary
protected.
This means that other classes can't access fields directly. Such protection
is part of information hiding, an important software design
strategy.
Book
class.
public class Book {
// +--------+--------------------------------------------------
// | Fields |
// +--------+
/** The title of the book. */
protected String title;
/** The binding of the book. */
protected Binding binding;
/** The authors of the book. */
protected AuthorList authors;
/** The price of the book. */
protected float price;
/** The condition of the book. */
protected String condition;
// ...
} // class Book
Point
class.
/**
* A point in two-space.
*/
public class Point {
// +--------+--------------------------------------------------
// | Fields |
// +--------+
/** The x coordinate. */
protected double x;
/** The y coordinate. */
protected double y;
// ...
} // Point()
this.fieldName
// Set the x coordinate of the current point to 0. this.x = 0.0; // Set the y coordinate of the current point to the x coordinate // of the current point. this.y = this.x;
Point class.
/** Create a new point with specified x and y coordinates. */
public Point(double xcoord, double ycoord) {
this.x = xcoord;
this.y = ycoord;
} // Point(double,double)
Point class in which the user does not have to specify
the x and y coordinates (we'll initialize them to 0).
Point class that takes
no parameters.
/** Create the point (0,0). */
public Point() {
this.x = 0.0;
this.y = 0.0;
} // Point()
Begin lab J3. You should plan to do sections J3.2, J3.3, J3.4, J3.5 and J3.7. We will continue the lab on Wednesday.
You may also do the other sections, but are not required to do so.
Tuesday, 10 August 1999
Monday, 6 September 1999
Tuesday, 7 September 1999
Back to Classes and Objects. On to Even More Classes and Objects.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99F/Outlines/outline.07.html
Source text last modified Tue Sep 7 10:48:00 1999.
This page generated on Tue Sep 21 11:09:46 1999 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu