Transcript Classes

Classes
Preparation
•
Scene so far has been background material and experience
– Computing systems and problem solving
– Variables
– Types
– Input and output
– Expressions
– Assignments
– Objects
– Standard classes and methods
Ready
•
Experience what Java is really about
– Design and implement objects representing information and
physical world objects
Object-oriented programming
•
Basis
– Create and manipulate objects with attributes and behaviors
that the programmer can specify
•
Mechanism
– Classes
•
Benefits
– An information type is design and
implemented once and reused as
needed
• No need reanalysis and re-justification of the
representation
Static variables and constants
// shared resource for all AirConditioner objects
static public final int OFF = 0;
Static public final int ON = 1;
static public final int LOW = 0;
Static public final int HIGH = 1;
static public final int DEFAULT_TEMP = 72;
• Every object in the class has access to the same static variables
and constants
– A change to a static variable is visible to all of the objects in
the class
– Examples StaticDemo.java and DemoStatic.java
Instance variables
• Instance variables are always initialized as soon the object
comes into existence
– If no value is specified
• 0 used for numeric variables
• false used for logical variables
• null used for object variables
• The constructor configures the object
• Examples InitializeDemo.java