Object Oriented Programming Flashcards
1
Q
Object
A
- “a location in memory having a valve and reference by an identifier”
- have state (data) and behaviours (methods)
2
Q
Class and how to define
A
- template for an object
To Define:
- class name
- state: attributes (defined by variables)
- behaviours: actions of objects (defined by methods)
3
Q
Variables and two types of variables
A
- variables define state in a class - store data, fields, attributes
Types of Variables
- Instance - each object has its own copy of instance variables in the class
- Class - declared with keyword static, only one copy of a class variable is maintained for all objects to refer to
4
Q
Methods in a Class
A
- Accessor - Used to determine value of a variable (getter method)
- Modifier - used to change the value of a variable (setter method)
- Helper - called from within a class by other methods
5
Q
Constructors
A
- used to create an instance of an object
- have same name as the class
- a class can have more than one constructor (method overloading)
- used once per object - only to create or instantiate an object
6
Q
Inheritance
A
- class that is derived from another class inherits state and behaviours from that other class
- subclass (or child) automatically takes on all behaviors and attributes of its base class (parent)
- base class defines all the common features , subclasses inherit common feature
- Single Inheritance - you can only extend one class
7
Q
Subclass Initialization
A
- to initialize a subclass - must ensure we initialize all the state attributes that were inherited for super class
- in a default constructor we can invoke the superclass constructor by using keyword: super