Académique Documents
Professionnel Documents
Culture Documents
2- Objects 2- Objects
• An object has: • An object has:
– state - descriptive characteristics – state - descriptive characteristics
– behaviors - what it can do (or what can be done to it) – behaviors - what it can do (or what can be done to it)
• The state of a bank account includes its account number and its current • The state of a bank account includes its account number and its current
balance balance
• The behaviors associated with a bank account include the ability to make • The behaviors associated with a bank account include the ability to make
deposits and withdrawals deposits and withdrawals
• Note that the behavior of an object might change its state • Note that the behavior of an object might change its state
3- Classes 3- Classes
• An object is defined by a class • An object is defined by a class
• A class is the blueprint of an object • A class is the blueprint of an object
• The class uses methods to define the behaviors of the object • The class uses methods to define the behaviors of the object
• The class that contains the main method of a Java program represents the • The class that contains the main method of a Java program represents the
entire program entire program
• A class represents a concept, and an object represents the embodiment of • A class represents a concept, and an object represents the embodiment of
that concept that concept
• Multiple objects can be created from the same class • Multiple objects can be created from the same class
7- Constants 7- Constants
A constant is an identifier that is similar to a variable except that it holds A constant is an identifier that is similar to a variable except that it holds
the same value during its entire existence the same value during its entire existence
As the name implies, it is constant, not variable As the name implies, it is constant, not variable
The compiler will issue an error if you try to change the value of a constant The compiler will issue an error if you try to change the value of a constant
In Java, we use the final modifier to declare a constant In Java, we use the final modifier to declare a constant
final int MIN_HEIGHT = 69; final int MIN_HEIGHT = 69;
8- Constants 8- Constants
• Constants are useful for three important reasons • Constants are useful for three important reasons
• First, they give meaning to otherwise unclear literal values • First, they give meaning to otherwise unclear literal values
– For example, MAX_LOAD means more than the literal 250 – For example, MAX_LOAD means more than the literal 250
• Second, they facilitate program maintenance • Second, they facilitate program maintenance
– If a constant is used in multiple places, its value need only be – If a constant is used in multiple places, its value need only be
updated in one place updated in one place
• Third, they formally establish that a value should not change, avoiding • Third, they formally establish that a value should not change, avoiding
inadvertent errors by other programmers inadvertent errors by other programmers