Object Oriented programming Flashcards

Whats OOP? what are the 4 Concepts of OOP? What is inheritance?

1
Q

What is Object Oriented Programming (OOPs)?

A

Object Oriented Programming (also known as OOPs) is a programming paradigm where the complete software operates as a bunch of objects talking to each other. An object is a collection of data and the methods which operate on that data.

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

Why OOPs?

A

The overall understanding of the software is increased as the distance between the language spoken by developers and that spoken by users.

Object orientation eases maintenance by the use of encapsulation. One can easily change the underlying representation by keeping the methods the same.

The OOPs paradigm is mainly useful for relatively big software.

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

What is a Class?

A

A class is a building block of Object Oriented Programs.
It is a user-defined data type that contains the data members and member functions that operate on the data members.
It is like a blueprint or template of objects having common properties and methods

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

What is an Object?

A

An object is an instance of a class. Data members and methods of a class cannot be used directly. We need to create an object (or instance) of the class to use them. In simple terms, they are the actual world entities that have a state and behavior.

Python Example:
class Student:
def __init__(self, studentName, studentSurname, studentRollNo):
self.name = studentName
self.surname = studentSurname
self.rollNo = studentRollNo

def getStudentDetails(self): 
    print("The name of the student is", self.name, self.surname) 
    print("The roll no of the student is", self.rollNo) 

student1 = Student(“Vivek”, “Yadav”, 20)
student1.getStudentDetails()

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

What are the main features of OOPs?

A

Encapsulation
Data Abstraction
Polymorphism
Inheritance

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

What is Encapsulation?

A

Encapsulation is the binding of data and methods that manipulate them into a single unit such that the sensitive data is hidden from the users
It is implemented as the processes mentioned below:

Data hiding: A language feature to restrict access to members of an object. For example, private and protected members in C++.
Bundling of data and methods together: Data and methods that operate on that data are bundled together. For example, the data members and member methods that operate on them are wrapped into a single unit known as a class.

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

What is Abstraction?

A

Abstraction is similar to data encapsulation and is very important in OOP. It means showing only the necessary information and hiding the other irrelevant information from the user. Abstraction is implemented using classes and interfaces.

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

What is Polymorphism?

A

The word “Polymorphism” means having many forms. It is the property of some code to behave differently for different contexts. For example, in C++ language, we can define multiple functions having the same name but different working depending on the context.

Polymorphism can be classified into two types based on the time when the call to the object or function is resolved. They are as follows:

A. Compile Time Polymorphism
B. Runtime Polymorphism

A) Compile-Time Polymorphism

Compile time polymorphism, also known as static polymorphism or early binding is the type of polymorphism where the binding of the call to its code is done at the compile time. Method overloading or operator overloading are examples of compile-time polymorphism.

B) Runtime Polymorphism

Also known as dynamic polymorphism or late binding, runtime polymorphism is the type of polymorphism where the actual implementation of the function is determined during the runtime or execution. Method overriding is an example of this meth

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

What is Inheritance? What is its purpose?

A

The idea of inheritance is simple, a class is derived from another class and uses data and implementation of that other class. The class which is derived is called child or derived or subclass and the class from which the child class is derived is called parent or base or superclass.

The main purpose of Inheritance is to increase code reusability. It is also used to achieve Runtime Polymorphism.

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

What are access specifiers? What is their significance in OOPs?

A

Access specifiers are special types of keywords that are used to specify or control the accessibility of entities like classes, methods, and so on. Private, Public, and Protected are examples of access specifiers or access modifiers.
The key components of OOPs, encapsulation and data hiding, are largely achieved because of these access specifiers.

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

What are the advantages OOPs?

A

OOPs provides enhanced code reusability.

The code is easier to maintain and update.

It provides better data security by restricting data access and avoiding unnecessary exposure.

Fast to implement and easy to redesign resulting in minimizing the complexity of an overall program.

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

Disadvantages of OOPs

A

The programmer should be well-skilled and should have excellent thinking in terms of objects as everything is treated as an object in OOPs.

Proper planning is required because OOPs is a little bit tricky.

OOPs concept is not suitable for all kinds of problems.

The length of the programs is much larger in comparison to the procedural approach.

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

What other paradigms of programming exist besides OOPs?

A
  1. Imperative Programming Paradigm
    It is a programming paradigm that works by changing the program state through assignment statements. The main focus in this paradigm is on how to achieve the goal. The following programming paradigms come under this category:

Procedural Programming Paradigm: This programming paradigm is based on the procedure call concept. Procedures, also known as routines or functions are the basic building blocks of a program in this paradigm.
Object-Oriented Programming or OOP: In this paradigm, we visualize every entity as an object and try to structure the program based on the state and behavior of that object.
Parallel Programming: The parallel programming paradigm is the processing of instructions by dividing them into multiple smaller parts and executing them concurrently.
2. Declarative Programming Paradigm
Declarative programming focuses on what is to be executed rather than how it should be executed. In this paradigm, we express the logic of a computation without considering its control flow. The declarative paradigm can be further classified into:

Logical Programming Paradigm: It is based on formal logic where the program statements express the facts and rules about the problem in the logical form.
Functional Programming Paradigm: Programs are created by applying and composing functions in this paradigm.
Database Programming Paradigm: To manage data and information organized as fields, records, and files, database programming models are utilized.

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

What are some commonly used Object Oriented Programming Languages?

A

C++
Java
Python
Javascript
C#
Ruby

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

What are the different types of Polymorphism?

A

A) Compile-Time Polymorphism
Compile time polymorphism, also known as static polymorphism or early binding is the type of polymorphism where the binding of the call to its code is done at the compile time. Method overloading or operator overloading are examples of compile-time polymorphism.

B) Runtime Polymorphism
Also known as dynamic polymorphism or late binding, runtime polymorphism is the type of polymorphism where the actual implementation of the function is determined during the runtime or execution. Method overriding is an example of this method.

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

What is the difference between overloading and overriding?

A

A compile-time polymorphism feature called overloading allows an entity to have numerous implementations of the same name. Method overloading and operator overloading are two examples.

Overriding is a form of runtime polymorphism where an entity with the same name but a different implementation is executed. It is implemented with the help of virtual functions.

17
Q

Are there any limitations on Inheritance?

A

Yes, there are more challenges when you have more authority. Although inheritance is a very strong OOPs feature, it also has significant drawbacks.

As it must pass through several classes to be implemented, inheritance takes longer to process.
The base class and the child class, which are both engaged in inheritance, are also closely related to one another (called tightly coupled). Therefore, if changes need to be made, they may need to be made in both classes at the same time.
Implementing inheritance might be difficult as well. Therefore, if not implemented correctly, this could result in unforeseen mistakes or inaccurate outputs.

18
Q

What different types of inheritance are there?

A

Single Inheritance: Child class derived directly from the base class
Multiple Inheritance: Child class derived from multiple base classes.
Multilevel Inheritance: Child class derived from the class which is also derived from another base class.
Hierarchical Inheritance: Multiple child classes derived from a single base class.
Hybrid Inheritance: Inheritance consisting of multiple inheritance types of the above specified.

19
Q

What is an interface?

A

A unique class type known as an interface contains methods but not their definitions. Inside an interface, only method declaration is permitted. You cannot make objects using an interface. Instead, you must put that interface into use and specify the procedures for doing so.

20
Q

How is an abstract class different from an interface?

A

Both abstract classes and interfaces are special types of classes that just include the declaration of the methods, not their implementation. An abstract class is completely distinct from an interface, though.

21
Q

Is it always necessary to create objects from class?

A

No. If the base class includes non-static methods, an object must be constructed. But no objects need to be generated if the class includes static methods. In this instance, you can use the class name to directly call those static methods.

22
Q

How much memory does a class occupy?

A

Classes do not use memory. They merely serve as a template from which items are made. Now, objects actually initialize the class members and methods when they are created, using memory in the process.

23
Q

What is Constructor?

A

A constructor is a block of code that initializes the newly created object. A constructor resembles an instance method but it’s not a method as it doesn’t have a return type. It generally is the method having the same name as the class but in some languages, it might differ. For example:

In python, a constructor is named __init__.

In C++ and Java, the constructor is named the same as the class name.

24
Q

What is a destructor?

A

A destructor is a method that is automatically called when the object is made of scope or destroyed.

In C++, the destructor name is also the same as the class name but with the (~) tilde symbol as the prefix.

In Python, the destructor is named __del__.

25
Q

Can we overload the constructor in a class?

A

We can overload the constructor in a class. In fact, the default constructor, parameterized constructor, and copy constructor are the overloaded forms of the constructor.

26
Q

Can we overload the destructor in a class?

A

No. A destructor cannot be overloaded in a class. The can only be one destructor present in a class.

27
Q

What is the virtual function?

A

A pure virtual function, also known as an abstract function is a member function that doesn’t contain any statements. This function is defined in the derived class if needed.