[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Back to Classes and Objects. On to Even More Classes and Objects.
Held Friday, January 29
Summary
Contents
Notes
main method) creates
objects and tells them what to do.
Point class has a print method,
and pt is a Point, you would use
pt.print(...).
pt is a
Point. Hence, I'll look at the instructions for
the print in the Point class.''
% mkdir dirname
% cd dirname
% pwd
% ls -F
% ls -F dirname
% cd /home/youraccount
% mv file dirname
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;
// ...
} // 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()
Do Lab J3.
History
Back to Classes and Objects. On to Even More Classes and Objects.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [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/99S/Outlines/outline.04.html
Source text last modified Fri Mar 12 13:06:34 1999.
This page generated on Fri Mar 12 13:12:47 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu