reference OOP Flashcards

1
Q

What is Inheritance?

A

A class can directly inherit from only one class, the superclass.

A class can have only one direct superclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is encapsulation?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is overloading?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is overriding?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a constructor?

A

methods that are called upon object creation, used to initialize data in a new object

Same name as the class, can have multiple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is “this” keyword

A
  1. used to refer to the current object
  2. Used to call a constructor from within another constructor in the same class
  3. Used to pass a reference of the current object to another object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is abstraction?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

static data members, methods, constants, and initializers reside with a class and not instances of classes

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a static data member?

A

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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a static method?

A

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();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what are static constants?

A

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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is an interface?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly