Fundamentals of oops Flashcards

1
Q

difference between pop and oops

A

pop has top down approach and oops has bottom up approach
pop focuses on functions and oops on data
pop the code is divided into modules and data can be accessed within this module if not it is declared globally and is prone to changes
in oops data is secured as data and functions are combined into a single unit called as class where the data can be accessed by its associated method it makes the data secure

Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP) based on the points you mentioned:

  1. Approach:
    POP:
    Follows a top-down approach, starting with the main function and breaking down tasks into smaller sub-functions.
    OOP:
    Uses a bottom-up approach, focusing on creating reusable objects and classes before building the overall program.
  2. Focus:
    POP:
    Primarily focuses on functions (procedures). The main goal is to create a sequence of tasks that the program performs.
    OOP:
    Emphasizes data and objects. It focuses on modeling real-world entities using classes and objects.
  3. Data Handling:
    POP:
    Data is often shared among functions. If data needs to be accessed globally, it is declared as a global variable, making it prone to changes and less secure.
    OOP:
    Data is encapsulated within objects, and access is controlled via methods. This promotes data security and reduces the chances of unintended modifications.
  4. Modularity:
    POP:
    Code is organized into modules (functions). However, these modules are not self-contained, as they may rely on global data.
    OOP:
    Code is structured into classes, which are self-contained units with data (attributes) and methods (functions). This increases modularity and code reusability.
  5. Security:
    POP:
    Less secure because data is exposed to the entire program.
    OOP:
    More secure due to data encapsulation. Data is hidden inside classes and only accessible through specific methods (getters and setters).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Characteristics of OOPS

A

Classes
Objects
Encapsulation
Abstraction
Inheritance
Data hiding
Polymorphism

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

What are classes and objects?

A

Implementation of abstract datatype

Classes are user defined datatype

it consist of dm and mf

implements: encapsulation, abstraction and data hiding

it is a blueprint of objects

we can reuse a class in any project

Object is instance of a class

it is variable of class datatype

it has a unique: name, state and behaviour

it has getters and setters

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

What are modifiers and selectors?

A

Modifiers/ Setters are methods that changes the state of an objects
Selectors/Getters access the state of an object but does not make any changes

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

What is encapsulation?

A

Primary purpose: ignores complexities, focuses on “what”it does rather than “how” it does!”

Encapsulation is combining the data and the function together it supports data security.
The data members can be accessed by the associated member functions only

Encapsulation helps in protecting the internal state of the object from unauthorized access and modification.

Data Hiding: using access modifiers (like private in Java). This ensures that data cannot be accessed directly.

Getter and Setter Methods: we control how the data is accessed or modified.

Encapsulation allows us to focus on what something does without considering the complexities of how it works.

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

Data Abstraction

A

Abstraction:
primary purpose :ignores irrelevant information

allows us to consider complex ideas while ignoring irrelevant detail that would confuse us

Only essential features are represented, hides unnecessary information and ADT is implementation of Data abstraction

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

Inheritance

A

it is the concept of oops that allows one class to inherit the properties and methods of another class

this enables code reusability and creation of specialized classes based on a general class.

use of inheritance :
code reusability
maintenance
polymorphism

Single Inheritance: One child class inherits from one parent class.

Multilevel Inheritance: A class inherits from a child class, forming a chain (e.g., A → B → C).

Hierarchical Inheritance: Multiple classes inherit from a single parent class.

Multiple Inheritance (Supported in C++): A child class inherits from more than one parent class. In Java, this is achieved using interfaces.

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

Polymorphysm

A

a way to perform a single action in different ways.

polymorphism lets objects behave differently even when using the same method name.

Types of Polymorphism
Compile-time polymorphism (Method Overloading):#have different parameter..

Achieved using method overloading.
Multiple methods have the same name but different parameters (number, type, or order).
Decided at compile time.

Runtime polymorphism (Method Overriding):#providing specific implementation of base class.

Achieved using method overriding.
A child class provides a specific implementation of a method that is already defined in its parent class.
Decided at runtime.

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

Data Hiding

A

Using access modifers : private public and protected we expose only what is necessary

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

Model Real world object

A

include <iostream></iostream>

#include <string></string>

using namespace std;

class Employee {
private:
string name;
int id;
double salary;

public:
// Constructor
Employee(string empName, int empId, double empSalary) {
name = empName;
id = empId;
salary = empSalary;
}

// Getter functions
string getName() {
    return name;
}

int getId() {
    return id;
}

double getSalary() {
    return salary;
}

// Setter functions
void setName(string empName) {
    name = empName;
}

void setId(int empId) {
    id = empId;
}

void setSalary(double empSalary) {
    salary = empSalary;
}

// Function to display employee details
void displayEmployeeDetails() {
    cout << "Employee Name: " << name << endl;
    cout << "Employee ID: " << id << endl;
    cout << "Employee Salary: $" << salary << endl;
} };

int main() {
// Create an Employee object
Employee emp1(“John Doe”, 101, 50000);

// Display employee details
emp1.displayEmployeeDetails();

// Modify employee details using setter functions
emp1.setName("Jane Smith");
emp1.setSalary(55000);

cout << "\nUpdated Employee Details:\n";
emp1.displayEmployeeDetails();

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

types of objects

A

external obj usfing extern keyword
local obj : in same block
static obj: retains previous value for same call
global obj: used within the same file
Dynamic obj: defined at runtime

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

Kinds of relationship

A

association, aggregation, generalisation, specialisation, composition

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

Association

A

Definition: # relation independent classes

indicate the relationship between two independent classes; the relationship may be one-to-one, one-to-many, or many-to-many, but it need not indicate ownership.

Association represents a relationship between two objects where both objects can exist independently, and each object can interact with the other.

Example: A Student class and a Course class. A student can enroll in a course, but both objects can exist without the other.

Types of Association:
One-to-One: One instance of a class is associated with exactly one instance of another class (e.g., Person and Passport).
One-to-Many: One instance of a class is associated with multiple instances of another class (e.g., Teacher and Students).
Many-to-Many: Multiple instances of a class are associated with multiple instances of another class (e.g., Student and Courses)

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

Aggregation

A

Aggregation: #one obj is part of other and both can exist independently

Definition: Aggregation is a special form of association where one object is a “whole” and the other is a “part”, but the part can exist independently of the whole.

Example: A University class can have multiple Department objects. If the university closes, the departments still exist as individual entities.
Characteristics: It represents a “Has-A” relationship. The “whole” object can exist without the “part”, but the part can exist without the whole.

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

Specialisation

A

Specialization:
Definition: Specialization is the reverse of generalization. It is the process of creating a more specialized subclass from a general superclass. A subclass is more specific and can have additional features or methods than the superclass.
Example: A Car class can specialize a Vehicle class, where Car adds specific features like numberOfDoors or engineType.

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

Generalisation

A

Generalization:
#shared characteristics…
Definition: Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. It represents an “Is-A” relationship.
Example: A Dog and Cat class can both inherit from an Animal class. The Animal class holds shared attributes like name and age, while Dog and Cat have additional specific properties or methods.
Characteristics: It’s the abstraction or creation of a base class from more specific subclasses.

17
Q

Composition

A

Composition:
Definition: Composition is a stronger form of aggregation. It represents a relationship where one object is a part of another object, and if the parent object is destroyed, the child objects are also destroyed. It’s a “Has-A” relationship with a tighter coupling between objects.
Example: A Library class can have multiple Book objects. If the Library is deleted, the Books will also be deleted since they cannot exist without the library.
Characteristics: The part cannot exist without the whole. This is sometimes called a “strong” aggregation.

18
Q

Advantages and Disadvantages of OOPS

A

Advantages:
Modularity and maintainability.
Reusability through inheritance.
Easier debugging and troubleshooting.
Data security and real-world modeling.
Scalability and flexibility.

Disadvantages:
Can introduce unnecessary complexity for simple applications.
Performance overhead due to objects and method calls.
Steep learning curve for beginners.
Potential for over-engineering or tight coupling if not carefully designed.

19
Q

what is message

A

function/method
message is a method call or request sent to an object, asking it to perform a specific action

20
Q

explain all kinds of relationships

A

Association: General relationship between classes; both can exist independently.
Aggregation: A “whole-part” relationship, where the part can exist independently.
Composition: A “whole-part” relationship, but the part cannot exist without the whole.
Generalization: Creating a more generalized superclass from specific subclasses, indicating an “Is-A” relationship.
Specialization: The reverse of generalization, where a subclass adds more specific functionality to a generalized class.

21
Q

how obj of one class can interact with obj of another class

A

using methods

22
Q

What is compile-time ?
what is runtime?

A

Compile Time: Compile time refers to the stage at which the source code written in a programming language is translated into machine code. This process involves checking the code for errors, syntax, and semantic correctness.

Runtime: Runtime, on the other hand, is the period during which the compiled code is executed by the computer. This is the stage at which the program is actually running, processing user input, and performing calculations.