[an error occurred while processing this directive]
[an error occurred while processing this directive]
University of Washington, AP/CS A
Lab 5: arrays
Except where otherwise noted, the contents of this document are
Copyright 2013 Stuart Reges and Marty Stepp.
lab document created by Marty Stepp, Stuart Reges and Whitaker Brand
Today's lab
Goals for this lab:
- write our own new classes of objects
- declare fields, methods, and constructors
- understand the difference between class code and client code
- Where you see this icon, you can click it to check the problem in Practice-It!
Declaring a class (syntax)
public class ClassName {
// fields
fieldType fieldName;
// methods
public returnType methodName() {
statements;
}
}
A couple things look different than programs for past homeworks:
- no
main
method. It won't be run like a client program.
- methods don't have the
static
keyword in the header.
- variables declared outside of any method (fields) are visible in every method.
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]