General Object-Oriented Programming Flashcards

1
Q

What is a class?

A

grouping of variables and methods in a source code file, from which objects can be created. Class is a grouping of variables and methods in a source code file that acts as a template/ blueprint for creating objects

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

What is an interface?

A

defines methods and holds a group of abstract methods and properties, is used to specify a behavior that classes must implement. ex appliances can all plug into a power outlet

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

What is encapsulation?

A

binds data and it’s related methods together within a class. It also protects the data by making fields private and giving access to them only through their related methods ex) bank account

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

What is inheritance?

A

when one class adopt the properties and methods of another class ex) dog and duck are both animals, both make sound and movement but differently

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

What is polymorphism?

A

the ability of an object to take on many forms ex) woman is a sister, friend, employee

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

***Why would you use an interface instead of inheritance?

A

you can inherit many interfaces, but only one base class ex) base discount, birthday discount, military discount)

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

What’s the difference between a class and an interface?

A

A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. A class may contain abstract methods, concrete methods. An interface contains only abstract methods.

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

What’s the difference between a class and an object?

A

Class is a template or blueprint to a house, object is an instance of a class, has their own data, the object is the house

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

Give me an example of where you might want to apply inheritance

A

Horse, Dog, Elephant inherits from animal

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

Give me an example of where you might want to apply interfaces

A

two classes for an alarm, one is a phone and one is an alarm clock but they can both be used for alarms or applicances can do different things but all are able to plug into a wall outlet

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

What is an abstract class?

A

a restricted class that “shows” only essential attributes and “hides” unnecessary information, cannot be used to create objects ex) travel abstract class is country and can use an interface to say iFlyable or iTrainable

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

What is a static method?

A

a method that only belongs that one class which prevents inheritance, is not stored

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

What is an Array?

A

collection of elements of the same type, can be individually referenced by using an index to a unique identifier, length cannot be changed

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

What is a static class?

A

a class that cannot be instantiated

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

define refactoring

A

allows you to change the code structure without changing or affecting what the code itself actually does// making changes to the code without changing its function, like changing parameter or variable names ex change var name from name to firstName to be more descriptive and differentiate between first, middle and last name

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

What is Functional Programming? How is it different from object-oriented programming?

A

In functional programming, data cannot be stored in objects, and it can only be transformed by creating functions. In object-oriented programming, data is stored in objects.