OOP Midterms

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

1/93

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.

94 Terms

1
New cards

Object-oriented programming

a computer programming model that organizes software design around data, or objects rather than functions and logic.

2
New cards

Object

a data field that has unique attributes and behavior.

3
New cards

Benefits of OOP

Reusability, scalability, and efficiency

4
New cards

Data Modeling

  • First step in OOP

  • collect all of the objects a programmer wants to manipulate and identify how they relate to each other

5
New cards

Example of OOP

  • The object is a human being, who is described by properties like name and address.

<ul><li><p>The object is a human being, who is described by properties like name and address.</p></li></ul><p></p>
6
New cards

Classes

  • are user-defined data types that act as the blueprint for individual objects, attributes, and methods

7
New cards

Objects

  • are instances of a class created with specifically defined data.

  • when class is defined initially, the description is the only _____ that is defined.

8
New cards

Methods

  • are functions that objects can perform.

  • they are defined inside a class that describe the behaviors of an object.

9
New cards

Instance Methods

subroutines contained in an object

10
New cards

Attributes

  • represent the state of an object

  • they are the characteristics that distinguish classes.

11
New cards

Encapsulation

  • states that all important information is contained inside an object and only select information is exposed.

  • the implementation and state of each object are privately held inside a defined class.

12
New cards

Abstraction

objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code.

13
New cards

Inhertiance

  • classes can reuse code and properties from other classes

  • relationships and subclasses between objects can be assigned, enabling developers to reuse common logic while still maintaining a unique hierarchy.

14
New cards

Polymorphism

  • objects are designed to share behaviors, and they can take on more than one form.

  • The program determines which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code.

  • enables different types of objects to pass through the same interface.

15
New cards

Syntax

set of rules that define how words and punctation are organized in a programming language

16
New cards

Coupling

  • is the degree to which software elements are connected to one another.

  • if a class has its attribute change, then any other coupled class also changes.

17
New cards

Association

  • is the connection between one or more classes.

  • can be one to one, many to many, one to many or many to one

18
New cards

Advantages of OOP

  • Modularity

  • Reusability

  • Flexibility and Extensibility

  • Encapsulation

  • Abstraction

19
New cards

Modularity

  • breaking down a complex system intro smaller, manageable units (classes and objects).

  • Each class represents a specific functionality, making it easier to understand, maintain, and update the codebase.

20
New cards

Reusability

  • OOP facilities code ______ through inheritance and polymorphism.

  • inheritance allows a subclass to inherit properties and behaviors from a superclass, reducing code duplication

  • Polymorphism enables objects to be treated as instances of their superclass, enhancing flexibility and extensibility,

21
New cards

Flexibility and Extensibility

  • provides ____ and ___ by allowing developers to add new features or modify existing ones without affecting the entire codebase.

22
New cards

Encapsulation

is the key principle of OOP that encapsulates data (attributes) and methods (functions) with a single unit (class).

23
New cards

Abstraction

focuses on hiding complex implementation details and exposing only essential features to users.

24
New cards

Simula

the first object-oriented programming language

25
New cards

Pure OOP languages

  • Ruby

  • Scala

  • JADE

  • Emerald

26
New cards

Primarily for OOP Languages

  • Java

  • Python

  • C++

27
New cards

Languages that pair with OOP

28
New cards

Benefits of OOP

  • Modularity

  • Reusability

  • Productivity

  • Easily upgradable and scalable

  • Interface Descriptions

  • Security

  • Flexibility

  • Code maintenance

  • Lower cost

29
New cards

Encapsulation

  • is a fundamental OOP principle that combines data and methods class

  • it allows implementation details to be hidden while exposing a public interface for interaction.

30
New cards

Example of Encapsulation

knowt flashcard image
31
New cards

How encapsulation is implemented

  • by declaring instance variables as private, restricting direct access.

  • public getter methods retrieve variable values, while setter methods modify them, enabling controlled access.

32
New cards

Encapsulation

  • is defined as the wrapping up of data under a single unit.

  • the variables or data of class are hidden from any other class and can be accessed only through any member function of its own class.

33
New cards

Private class

can hide its members or methods from the end user, using abstraction to hide implementation details, by combining data hiding and abstraction.

34
New cards

How to achieve encapsulation?

by declaring all the variables in the class as private and writing public methods in the class to set and get values of variables.

35
New cards

Inheritance

a mechanism in java by which one class is allowed to inherit the features (fields & methods) of another class.

36
New cards

Reasons on why we need Java Inheritance

  • Code Reusability

  • Method Overriding

  • Abstraction

37
New cards

Class

  • is a set of objects which shares common characteristics/behavior and common properties/attributes.

  • a blueprint or prototype from which objects are created.

38
New cards

Super Class/Parent Class

the class whose features are inherited is known as a superclass. (or base class/parent class)

39
New cards

Sub Class/Child Class

  • the class that inherits the other class is known as a subclass (or a derived class, extended class or child class).

  • has its own fields and methods on addition to the superclass fields and methods.

40
New cards

Reusability

  • inheritance supports the concept of “______”

  • when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class.

41
New cards

How to use inheritance in Java?

  • the extends keyword is used for ______ in java.

  • Using the extends keyword indicates you are derived from an existing class.

42
New cards

Subclass

During inheritance only the object of the _____ is created, not the superclass.

43
New cards

Types of Inheritance

  1. Single Inheritance

  2. Multilevel Inheritance

  3. Hierarchical Inheritance

  4. Multiple Inheritance

  5. Hybrid Inheritance

44
New cards

Single Inheritance

  • a sub-class is derived from only one super class.

  • it inherits the properties and behavior of a single-parent class

<ul><li><p>a sub-class is derived from only one super class.</p></li><li><p>it inherits the properties and behavior of a single-parent class</p></li></ul><p></p>
45
New cards

Multilevel Inheritance

  • a derived class will be inheriting a base class, and as well as the derived class also acts as the base class for other classes.

<ul><li><p>a derived class will be inheriting a base class, and as well as the derived class also acts as the base class for other classes.</p></li></ul><p></p>
46
New cards

Hierarchical Inheritance

one class serves as a superclass for more than one subclass.

<p>one class serves as a superclass for more than one subclass.</p>
47
New cards

Multiple Inheritance (Through Interfaces)

  • one class can have more than one superclass and inherit features from all parent classes.

  • note: java does not support ______ inheritances with classes. this is only achievable through interfaces.

<ul><li><p>one class can have more than one superclass and inherit features from all parent classes.</p></li><li><p>note: java does not support ______ inheritances with classes. this is only achievable through interfaces.</p></li></ul><p></p>
48
New cards

Hybrid Inheritance

  • is a mix of two or more of the above types of inheritance.

  • java does not support multiple inheritances with classes, ______ inheritance involving multiple inheritance is also not possible with classes.

  • it can be achieved through a combination of multilevel inheritance and hierarchical inheritance with classes, hierarchical and single inheritance with classes.

<ul><li><p>is a mix of two or more of the above types of inheritance.</p></li><li><p>java does not support multiple inheritances with classes, ______ inheritance involving multiple inheritance is also not possible with classes.</p></li><li><p>it can be achieved through a combination of multilevel inheritance and hierarchical inheritance with classes, hierarchical and single inheritance with classes.</p></li></ul><p></p>
49
New cards

IS-A

is a way of saying: this object is a type of that object.

<p>is a way of saying: this object is a type of that object.</p><p></p>
50
New cards

Sub-classes

in _____ we can inherit members as is, replace them, hide them, or supplement them with new members

51
New cards

Inherited Fields

The _____ ____ _can be used directly, just like any other fields.

52
New cards

New fields

We can declare ____ ____ in the subclass that are not in the superclass.

53
New cards

Inherited Methods

  • The _____ methods can be used directly as they are.

54
New cards

Instance Method

We can write a new _____ ____ in the subclass that has the same signature as the one in the superclass, thus overriding it.

55
New cards

Static method

W can write a new ____ ___ in the subclass the same signature as the one in the superclass, thus hiding it.

56
New cards

New methods

We can declare ____ ___ in the subclass that are not in the superclass.

57
New cards

Subclass Constructor

We can write a _____ ____ that invokes the constructor of the superclass, either, implicitly or by using the keyword super.

58
New cards

Advantages of Inheritance in Java

  1. Code Reusability

  2. Abstraction

  3. Class Hierarchy

  4. Polymorphism

59
New cards

Disadvantages of Inheritance in Java

  1. Complexity

  • can make the code more complex and harder to understand.

  1. Tight Coupling

  • creates a tight coupling between the superclass and subclass, making it difficult to make changes to the superclass without affecting the subclass.

60
New cards

Default Superclass

every class has one and only one direct ________ (single inheritance). In the absence of any other explicit _______, every class is implicitly a subclass of the Object class.

61
New cards

Super class can only be one

can have any number of subclasses but only one superclass.

62
New cards

Inheriting Constructors

inherits all the members (fields, methods, and nested classes) from its superclass.

63
New cards

Private member inheritance

  • a subclass does not inherit the private members of its parent class.

  • however, if the superclass has public or protected methods (getters and setters) for accessing its private fields, these can also be used by the subclass.

64
New cards

Polymorphism

  • means ‘having many forms’

  • refers to the ability of a message to be displayed in more than one form

  • it allows objects to behave differently based on their specific class type.

65
New cards

Types of Java Polymorphism

  • Complie-Time Polymorphism

  • Runtime Polymorphism

66
New cards

Compile-Time Polymorphism

  • also known as static polymorphism

  • is achieved by function overloading or operator overloading. (but java doesnt support operator overloading.

<ul><li><p>also known as static polymorphism</p></li><li><p>is achieved by function overloading or operator overloading. (but java doesnt support operator overloading.</p></li></ul><p></p>
67
New cards

Method Overloading

  • when there are multiple functions with the same name but different parameters then these functions are said to be overloaded.

  • functions can be overloaded by changes in the number of arguments or/and a change in the type of arguments.

68
New cards

Subtypes of Compile-time Polymorphism

  • Function overloading

  • Operator overloading

  • Template

69
New cards

Function Overloading

a feature in c++ and java where multiple functions can have the same name but with different parameter lists. the compiler will decide which function to call based on the number and types of arguments passed to the function.

70
New cards

Operator Overloading

a feature in c++ where the operators such as +, -. *, etc. can be given additional meanings when applied to user-defined data types.

71
New cards

Template

  • is a powerful feature in C++ that allows us to write generic functions and classes.

  • is a blueprint for creating a family of functions or classes.

72
New cards

Runtime Polymorphism

  • is known as dynamic method dispatch

  • a process in which a function call to the overridden method is resolved at runtime.

  • this can be done method overriding

73
New cards

Subtype of Run-Time Polymorphism

Virtual Functions

74
New cards

Virtual Functions

  • allows an object of a derived class to behave as if it were an object of the base class.

  • the derived class can override the _____ ____ of the base class to provide its own implementation.

  • the function call is resolved at runtime, depending on the actual type of object.

75
New cards

Advantages of Polymorphism

knowt flashcard image
76
New cards

Disadvantages of Polymorphism

knowt flashcard image
77
New cards

Subtyping vs Subclassing

  • OOP relies heavily on concepts of subtyping and subclassing.

  • Understanding these concepts is crucial for effectively writing reusable and maintainable code.

78
New cards

Subclassing

  • is a specific mechanism in OOP languages like Java that implements subtyping through inheritance.

  • inherits the attributes and methods of its superclass, establishing an “is-a” relationship

79
New cards

Subtyping

  • is a broader concept that deals with relationships between types.

  • it’s about the ability of one type to be substituted for another type in certain context.

  • is primarily achieved through inheritance and interfaces

80
New cards

Benefits of Subtyping with Interfaces

knowt flashcard image
81
New cards

Subclassing

  • is a specific implementation of subtyping through class hierarchies

  • involves creating a new class that inherits attributes and behaviors from an existing class, known as a superclass.

82
New cards

Key Characteristics of Subclassing

knowt flashcard image
83
New cards

Subtyping without Subclassing

knowt flashcard image
84
New cards

Polymorphism via Interfaces

knowt flashcard image
85
New cards

Abstraction

  • is the process of hiding the implementation details and only showing the essential functionality or features to the user.

  • this helps simplify the system by focusing on what the object does rather than how it does it.

86
New cards

How is abstraction achieved in Java?

  • by interfaces and abstract classes.

87
New cards

Abstract Class

  • is a class that is declared with an abstract keyword.

  • may or may not have all abstract methods. some of them can be concrete methods

  • can have parameterized constructors and the default constructor is always present in an abstract class.

88
New cards

Abstract Method

  • is a method that is declared without implementation

  • must always be redefined in the subclass, thus making overriding compulsory or making the subclass itself abstract.

89
New cards

Class

any ____ that contains one or more abstract methods must also be declared with an abstract keyword.

90
New cards

Instantiated

There can be no object of an abstract class. That is, an abstract class can not be directly ______ with the new operator.

91
New cards

Algorithm to Implement Abstraction

knowt flashcard image
92
New cards

Advantages of Abstraction

  • simplifies complex systems by hiding implementation details.

  • increases code reusability and maintainability

  • enhances security by exposing only essential features

  • improves modularity and separation of concerns.

  • provides a clear and user-friendly interface.

93
New cards

Disadvantages of Abstraction

  • it can add unnecessary complexity if overused.

  • may reduce flexibility in implementation.

  • makes debugging and understanding the system harder for unfamiliar users.

  • overhead from abstraction layers can affect performance.

94
New cards

Why do we use abstract?

it is used to simplify the complexity and make easier for both user and end users. we can use abstraction to hide details and show necessary parts.