reference OOP Flashcards
What is Inheritance?
A class can directly inherit from only one class, the superclass.
A class can have only one direct superclass
What is encapsulation?
The class is private, only accessible through the public interface.
Data hiding, using classes with member variables defined as private. Use accessor and mutator methods aka getters, and setters.
The purpose is to control data within each method to ensure another class cannot modify the private members.
What is overloading?
methods and constructors can be overloaded
two or more methods can have the same name but different arguments and return values(must have different arguments to be considered overloading).
what is overriding?
A subclass can override the methods it inherits.
Method contains the same signature(name and parameters) as the method in the superclass but it has different implementation details(method functionality)
Method cannot be final, private, or static
what is a constructor?
methods that are called upon object creation, used to initialize data in a new object
Same name as the class, can have multiple
what is “this” keyword
- used to refer to the current object
- Used to call a constructor from within another constructor in the same class
- Used to pass a reference of the current object to another object
what is abstraction?
methods and classes declared with keyword abstract
Base class, cannot be instantiated
all abstract methods must be defined in class that inherits it.. Alarm base class is abstract with method renderAlarm(). If DisplayAlaram extends Alaram it must contain renderAlarm
static data members, methods, constants, and initializers reside with a class and not instances of classes
true
what is a static data member?
stored in a single location in memory
used when only one copy of a data member is needed across all instances of a class
static int voterCount = 0; public Voter{voterCount++;} public static int getVoterCount(){ return voterCount; } ....int numVoters = Voter.voterCount;
what is a static method?
keyword static in the method declaration static
methods can only access static methods or variables because static methods are associated with a class, not an object.
class Anaylzer { public static it getVotesByAge() {...} } //to use Anaylzer.getBotesByAge();
what are static constants?
static constants are static members declared constant.
They have the keywords static and final
** A program cannot change them //Declaring a static constant static final int AGE_LIMIT =18;
what is an interface?
provides a set of declared public methods that do not have method bodies.
another class implements an interface and provides the body implementation
the interface provides capability, “blueprint” of a class, used to achieve abstraction, multiple inheritances
allow multiple methods to be used across the class hierarchy
Pro Tip: classes can implement mulitple interfaces, and interfaces can extend mulitple interfaces