Object Oriented programming Flashcards
Whats OOP? what are the 4 Concepts of OOP? What is inheritance?
What is Object Oriented Programming (OOPs)?
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.
Why OOPs?
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.
What is a Class?
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
What is an Object?
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()
What are the main features of OOPs?
Encapsulation
Data Abstraction
Polymorphism
Inheritance
What is Encapsulation?
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.
What is Abstraction?
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.
What is Polymorphism?
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
What is Inheritance? What is its purpose?
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.
What are access specifiers? What is their significance in OOPs?
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.
What are the advantages OOPs?
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.
Disadvantages of OOPs
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.
What other paradigms of programming exist besides OOPs?
- 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.
What are some commonly used Object Oriented Programming Languages?
C++
Java
Python
Javascript
C#
Ruby
What are the different types of 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 method.