Chapter 2: Object Oriented Programming (OOP)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/36

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.

37 Terms

1
New cards

What is Object-Oriented Programming (OOP)?

A programming paradigm that organizes code using objects and follows four main principles: abstraction, encapsulation, inheritance, and polymorphism.

2
New cards

What is abstraction?

Hiding complex implementation details and showing only essential features.

3
New cards

What is encapsulation?

Wrapping data and methods into a class and restricting access using access modifiers.

4
New cards

What is inheritance?

When a class inherits fields and methods from another class (a parent class).

5
New cards

What is polymorphism?

Using a single interface to represent different types, enabling method overriding and overloading.

6
New cards

What does abstraction focus on?

What an object does, not how it does it.

7
New cards

Why is abstraction useful?

It helps manage complexity and lets us use objects without knowing their internal workings.

8
New cards

How is abstraction implemented in Java?

Using abstract classes and methods.

9
New cards

What does encapsulation do?

Hides data and only allows controlled access through public methods.

10
New cards

How is encapsulation implemented in Java?

Using private variables and public getter/setter methods.

11
New cards

Why is encapsulation important?

It protects data from being changed incorrectly and bundles state + behaviour.

12
New cards

What does inheritance allow in Java?

A child class to reuse code from a parent class.

13
New cards

What kind of relationship is inheritance?

An "is-a" relationship.

14
New cards

What does a subclass inherit from its superclass?

All non-private fields and methods.

15
New cards

Can a subclass override inherited methods?

Yes — using the same method signature.

16
New cards

What does polymorphism allow?

A subclass object to be treated as an object of its parent class.

17
New cards

What are the two types of polymorphism?

Method overriding and method overloading.

18
New cards

Is this valid? Animal a = new Dog();

Yes — because Dog is an Animal.

19
New cards

Is this valid? Dog d = new Animal();

No — because not all Animals are Dogs.

20
New cards

What are UML class diagrams used for?

To visualize classes, their attributes, methods, and relationships.

21
New cards

What symbol means public in UML?

+

22
New cards

What symbol means private in UML?

-

23
New cards

How is an attribute shown in UML?

name : type

24
New cards

How is a method shown in UML?

methodName(parameters) : returnType

25
New cards

What is association?

A general relationship between two independent classes.

26
New cards

What is aggregation?

A "has-a" relationship where the contained object can exist independently.

27
New cards

What is composition?

A "has-a" relationship where the contained object cannot exist without the container.

28
New cards

Example of aggregation?

A Library has many Books, but a Book can exist on its own.

29
New cards

Example of composition?

A House has Rooms, and if the house is destroyed, so are the rooms.

30
New cards

What is bidirectionality?

Whether both classes in a relationship know about each other.

31
New cards

What is a unidirectional relationship?

Only one class holds a reference to the other.

32
New cards

What is a bidirectional relationship?

Both classes hold references to each other.

33
New cards

What is multiplicity in class relationships?

It describes how many instances of one class relate to instances of another.

34
New cards

What does 1 mean in multiplicity?

One-to-one relationship.

35
New cards

What does 0..1 mean?

Zero or one instance.

36
New cards

What does 0..* mean?

Zero or many (optional).

37
New cards

What does 1..* mean?

One or many (mandatory).