OOP Flashcards
What is a class?
A class is a blueprint that provides a definition of the attributes and methods of an object.
What is an object?
An object is something that we want to represent in our computer system and we model as a class. Examples of objects are students, dogs, invoices and trains.
What is encapsulation?
It is a form of data hiding. Data and functions are combined into a single unit (a class). The attributes of the class are kept private and public ‘getter’ and ‘setter’ methods are provided to manipulate these attributes.
What is polymorphism?
Two or methods with the same name but different implementations. Each object in oop owns its own behaviours. If you call a method on an object, it knows how to behave. Thus a triangle object when asked to draw itself, will draw a 3 sided object and a square will draw something with 4 equal length sides.
What is instantiation?
The process of making a instance of an object and assigning it to a reference variable.
What is a constructor?
It is a special method that is called implicitly or explicitly when a class is instantiated. It is used to provide initial values for the attributes - either default values or those passed in as parameters.
What is a reference variable?
A pointer to a memory location where an instance is stored.
What is inheritance?
This is where a class is derived from a super class (parent class). The derived class (child/sub class), inherits all of the properties (attributes and methods) of the parent class.
What is aggregation?
A form of association that defines a “has a” relationship. However, the two objects can exist separately so, if one is destroyed, the other can continue to exist. The reference to the owned object exists outside of the container.
What is composition?
A form of association that defines a “has a” relationship. The two objects cannot exist separately so, if one is destroyed, the other is also destroyed. The reference to the owned object exists only within the container. (it is usually instantiated by the owning objects constructor.
In a UML diagram, what are the access specifiers for public, private and protected?
+ public - private # protected
What is the difference between a private attribute and a protected attribute.
A private attribute can be accessed only by class methods. A protected attribute can also be accessed by derived (inherited) methods.
What type of relationship is shown in this UML diagram?
Inheritance
What type of relationship is shown in this UML diagram?
Composition
What type of relationship is shown in the UML diagram?
Aggregation