OOP

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

What is encapsulation?

Bundling data and methods that operate on the data into a single unit (class).

2
New cards

What’s a key benefit of encapsulation?

Protects data from unintended modification by restricting direct access.

3
New cards

What’s an example of encapsulation?

Using private variables and getter/setter methods in a class.

class Person:

def init(self, name):

self.__name = name # Private variable

def get_name(self): # Getter method

return self.__name

4
New cards

What is abstraction?

Hiding complex implementation details and exposing only what’s necessary.

5
New cards

What’s a key benefit of abstraction?

Simplifies usage and reduces code complexity.

6
New cards

What’s an example of abstraction?

Using abstract classes or interfaces.

from abc import ABC, abstractmethod

class Animal(ABC):

@abstractmethod

def make_sound(self):

pass # Forces subclasses to implement this method

7
New cards

What is inheritance?

Allowing a new class to inherit attributes and behaviors from an existing

class.

8
New cards

What’s a key benefit of inheritance?

Promotes code reuse and hierarchy.

9
New cards

What’s an example of inheritance?

Promotes code reuse and hierarchy.

class Dog(Animal):

def make_sound(self):

return "Woof!"

10
New cards

What is polymorphism?

Allowing different classes to be treated as instances of the same class through

a common interface.

11
New cards

What is a key benefit of polymorphism?

Flexibility and scalability in handling multiple object types.

12
New cards

What is an example of polymorphism?

Method overriding in subclasses.

def animal_sound(animal):

print(animal.make_sound()) # Can work with different

subclasses

dog = Dog()

animal_sound(dog) # Output: "Woof!"