oop Flashcards
(8 cards)
what is an object
An object is
* Something tangible (person, pen, mug
An object has state, behavior, identity
What is a class
A class is a blueprint or template for creating objects (instances). It
defines the structure and behaviour that its instances (objects) will
have.
Constructors
The constructor MUST have the same name as
the class name
* A class can have more than one constructor
instance variable
An instance variable can hold a single value
e.g. private double balance
Instance variables are typically defined as private
this facilitates information hiding between classes
more on access modifiers (e.g. private) later
information hiding essential in industry
instance Methods
- Instance methods represent the behavior and alter
the state of an object, they manipulate an object - Instance methods also provide the interface of
classes
different objects can communicate with each other via
their instance methods - To achieve this, instance methods are typically
defined as public
can be accessed by members of other classes
Method overloading
Instance methods can be overloaded, i.e. more than one
method can have the same name inside the same class
* For this to work, overloaded methods must have different
number of parameters, or parameters of different types
public void deposit(double amount)
public void deposit(double money)
2) public void deposit(double amount)
public void deposit(double amount, double interest
Access modifier
The declaration of an instance variable, a constructor, an
instance method (even of a class) begins with an access
modifier (public or private)
Public: the entity can be accessed by other classes
Private: the entity is only accessible from within the class
itself