Object Oriented Concepts Flashcards
What is an object?
something that can be described by both data attributes (e.g., age, weight) and behavior
(e.g., eat, talk).
Explain this class diagram
The
top compartment contains the name of the thing being modeled…in our case a cat. The next
compartment contains a list of the attributes we are including in our model. And the bottom
compartment contains a list of relevant behaviors.
what is a class?
programming construct used to create objects. It defines the structure and behavior (data and code) shared by a set of objects.
It creates a new data type.
What is encapsulation?
a protective wrapper that controls access to the code and data through a well-defined interface
what does it mean if something is a “member” of a class?
the code and data in the class. Member variables and member methods
whats the difference between a public and private method?
public can be accessed outside of the class. Private methods can only be accessed by code that is a member f hte class.
What is inheritance
process by which one object acquires the properties of another object.
Important because it supports the concept of hierarchical classification (e.g. dog inherits mammal inherits animal)
What is polymorphism?
“one interface multiple methods”
one interface used for a general class of actions
What relationship between a class and an object?
object is instance of a class.
Class is template for an object
what does ‘new’ operator do
dynamically allocates (meaninning allocates at run time) memory for an object
Box mybox = new Box();
Box mybox; // declare reference to object
mybox = new Box(); //allocates a Box object
What is a constructor?
Defines what occurs when an object of a class is created.
class name followed by parentheses specifies the constructor for the class
Explain this situation:
Box b1 = new Box();
Box b2 = b1;
Both point to same object. Changing b2 will update for b1 too.
Whats difference between parameter and argument?
parameter is the variable defined by the method that receives the value.
argument is the value passed to a method when its invoked
How write the constructor method?
same name as the class with capital
Box () {
….
}
explain ‘this’
refers to the current object
this.width = w