Foundations Flashcards

1
Q

What does OOP stand for?

A

Object-Oriented Programming

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

How does OOP organize code?

A

By using objects that combine data (properties) and actions (methods).

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

What are the four pillars of OOP?

A

Encapsulation, Abstraction, Inheritance, Polymorphism

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

What is Encapsulation?

A

Bundles data (properties) and methods that operate on it within an object.
Like a coffee maker - protects internal workings (water level) and controls access (setter methods).

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

What is Abstraction?

A

Hides complex details and shows essential functionalities. Like a TV - use turnOn without knowing how the image is displayed.

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

What is Inheritance?

A

Reuses code by creating new objects based on existing ones. A bird class inherits from animal (fly()), adding chirp().

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

What is Polymorphism?

A

Objects of different classes respond differently to the same method. Animal class with subclasses dog (bark()) and cat (meow()), both having a makeSound() method.

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

What are Classes and Objects in OOP?

A

A class is a blueprint that defines the properties and methods of similar objects. An object is an instance of a class, representing a specific entity with its own data and behavior.

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

What are the benefits of OOP?

A

OOP promotes code reusability, maintainability, modularity, and data protection by organizing code into objects with well-defined functionalities.

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

What is a Method in OOP?

A

A method is a function defined within a class that represents an action or behavior that the object can perform.

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

What is a Property in OOP?

A

A property is a characteristic of an object that holds data and can be accessed or modified by methods.

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

What are the different types of inheritance in OOP?

A

There are different types of inheritance like single inheritance (one subclass inherits from one superclass), multiple inheritance (subclass inherits from multiple superclasses), and hierarchical inheritance (forming a hierarchy of classes).

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

What is the difference between public, private, and protected access modifiers in OOP?

A

Access modifiers control access to an object’s properties and methods. Public allows access from anywhere, private restricts access to the class, and protected allows access from within the class and subclasses.

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

What is an Interface in OOP?

A

An interface defines a contract that specifies what methods a class must implement. It promotes loose coupling and enables polymorphism.

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

What is the difference between a Class and an Instance in OOP?

A

A class is the blueprint, while an instance (object) is the specific realization of that blueprint with its own data.

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

What is Abstraction in OOP achieved through?

A

Abstraction can be achieved through methods that hide internal implementation details and interfaces that define functionalities without specifying how they are implemented.

17
Q

What are the advantages of Encapsulation in OOP?

A

Encapsulation promotes data security by restricting direct access and improves code maintainability by keeping functionalities within a well-defined unit (object).

18
Q

What is Polymorphism beneficial for in OOP?

A

Polymorphism allows for flexible and dynamic behavior. You can write code that works with different objects without modifying it for each specific class.

19
Q

What are some challenges of using OOP?

A

OOP can introduce complexity if overused. Understanding relationships between objects and managing inheritance hierarchies can require careful planning.

20
Q

What is a constructor in OOP?

A

A constructor is a special method in a class that is called when an object is created. It’s used to initialize the object’s properties with starting values.

21
Q

What is the difference between static and non-static methods in OOP?

A

Non-static methods operate on data specific to an object instance. Static methods are associated with the class itself and can be accessed without creating an object.

22
Q

What is the role of getters and setters in OOP?

A

Getters and setters are methods used to control access to an object’s properties. Getters retrieve the property value, while setters modify it while potentially adding validation or security checks.