Tom Kelliher, CS 116
Oct. 6, 2000
Lab 4 write-up and applet due Monday. cs116l4@goucher.edu
PostLab 4 due Wednesday. cs116pl4@goucher.edu
Exam next Friday.
Read 5.3.
Lab 4.
Access, operators, and expressions.
What is a primitive type?
How do classes relate to primitive types?
Families of primitive types:
byte
, short
, int
, and long
.
float
and double
.
15.0
, -12.345e-13f
, 10.0e6
.
char
.
'a'
, ' '
, '\n'
, '\t'
, '\\ '
, '\''
,
'\"'
.
boolean
.
true
, false
.
class
, private
.
Not keywords: Applet
, GridLayout
.
Entities whose value we can change.
Recall: the public instance variables of an object can be accessed thus:
objectName.instanceVariableName
What are they?
Where are they?
What are they?
Where are they?
The region of code in which a variable is visible.
A local variable can shadow an instance variable.
Consider this example:
class Example { private int i = 1; public int k = 20; private static int l = 5; public void Method1() { int i = 2; i = 3; // Which i? // ... } private void Method2() { int j = 11; // ... } }
Scope of instance variable (or method): entire class.
Scope of local variable: from point of declaration until end of method.
Identifier names must be unique within a particular scope level.
How long does a variable exist?
static
and final
.
A static
instance variable becomes a class variable --- it
is shared by all class objects. How is this different from an instance
variable?
Consider two Example
objects and their relationship to the instance
and class variables.
Applying final
to an identifier means that it can not be changed.
Example:
static final double PI = 3.14159;