MIST 4600: Chapter 2

Object...

consists of some internal data items plus operations that can be performed on that data

An object's internal data...

called private fields, as the data is private to the object

The operations that can be called on an object are called...

public methods, as those operations can be called from outside the object

Class...

defines a type that groups data and methods to form an object - like a blueprint explaining how to create objects and an instruction manual explaining how to use an object

A class' public methods...

define the operations that can be performed on objects of that class type

Declare and create a new object of type PeopleCounter named passengerCounter

PeopleCounter passengerCounter = new PeopleCounter();

Declare and create two objects of type PeopleCounter named entranceCount and exitCount

PeopleCounter entranceCount = new PeopleCounter();
PeopleCounter exitCount = new PeopleCounter();

Call the printCount() method on a PeopleCounter object named studentCounter

studentCounter.printCount();

Variable declaration...

a statement that declares a new variable, specifying the variable's name and type
Ex; int userAge;

Assignment statement...

assigns the variable on the left-side of the = with the current value of the right-side expression
variableName = expression;
Ex: numApples = 8;

Identifiers...

A name created by a programmer for an item like a variable or method

Compound operators...

provide a shorthand way to update a variable, such as userAge += 1 being shorthand for userAge = userAge +1
Ex: -=, *=, /=, %=

method call...

a statement that invokes an object's method, allowing the program to perform a particular operation on that output

Writing a method call to perform an operation on an object

objectName.methodName();

Call the resetCount method on a PeopleCounter object named guestCounter

guestCounter.resetCount();

A class' public method...

are the operations that a program can directly invoke on objects of that class type; class interface

Programmers influence the behavior of methods by providing additional input values, called...

method argument

Write a method call that sets the number of bins for a Histogram object named coinFlipHistogram to 2

conFlipHistogram.setNumberOfBins(2);

Write a method call that sets the value of the bin 1 to the value 10 for a Histogram object named coinFlipHistogram

conFlipHistogram.setBinValue(1, 10);

Creating an object and assigning a variable with that object involves three parts:

1. Reference variable
2. new operator
3. Constructor

Reference variable

the first part of the statement, [Histogram gradesHistogram] declares a reference variable that can refer to an object. But, the variable declaration does not create an object.

Reference

a variable type that refers to an object - storing the memory address of an object

new operator

the next part of the statement, [new Histogram()], creates a new object. The new operator creates an object by allocating memory for the object and initializing the object by calling a constructor

constructor

is a special method for an object that is called whenever a new object is created, and is used to initialize the object's internal data. A class may define more than one constructor. The [Histogram()] part of the statement indicates which constructor shou

Mutator

method may modify ("mutate") the object, thereby changing the object's internal data

Accessor

accesses the object's data but does not modify the internal data