OOP Flashcards

1
Q

What is meant by the term OOPs?

A

OOPs refers to Object-Oriented Programming. It is the programming paradigm that is defined using objects. Objects can be considered as real-world instances of entities like class, that have some characteristics and behaviors.

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

What is the need for OOPs?

A
  • OOPs helps users to understand the software easily, although they don’t know the actual implementation.
  • With OOPs, the readability, understandability, and maintainability of the code increase multifold.
  • Even very big software can be easily written and managed easily using OOPs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is meant by Structured Programming?

A

Structured Programming refers to the method of programming which consists of a completely structured control flow. Here structure refers to a block, which contains a set of rules, and has a definitive control flow, such as (if/then/else), (while and for), block structures, and subroutines.

Nearly all programming paradigms include Structured programming, including the OOPs model

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

What are the main features of OOPs?

A
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Data Abstraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some advantages of using OOPs?

A
  • OOPs is very helpful in solving very complex level of problems.
  • Highly complex programs can be created, handled, and maintained easily using object-oriented programming.
  • OOPs, promote code reuse, thereby reducing redundancy.
  • OOPs also helps to hide the unnecessary details with the help of Data Abstraction.
  • OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach.
  • Polymorphism offers a lot of flexibility in OOPs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is OOPs so popular?

A

OOPs programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs - Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular

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

What is encapsulation?

A

One can visualize Encapsulation as the method of putting everything that is required to do the job, inside a capsule and presenting that capsule to the user. What it means is that by Encapsulation, all the necessary data and methods are bind together and all the unnecessary details are hidden to the normal user. So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.

Encapsulation can also be defined in two different ways:

1) Data hiding: Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object.
2) Data binding: Encapsulation is the process of binding the data members and the methods together as a whole, as a class.

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

What is Polymorphism?

A

Polymorphism is composed of two words - “poly” which means “many”, and “morph” which means “shapes”. Therefore Polymorphism refers to something that has many shapes.

In OOPs, Polymorphism refers to the process by which some code, data, method, or object behaves differently under different circumstances or contexts. Compile-time polymorphism and Run time polymorphism are the two types of polymorphisms in OOPs languages.

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

What is Compile time Polymorphism and how is it different from Runtime Polymorphism?

A

Compile Time Polymorphism: Compile time polymorphism, also known as Static Polymorphism, refers to the type of Polymorphism that happens at compile time. What it means is that the compiler decides what shape or value has to be taken by the entity in the picture.

Runtime Polymorphism: Runtime polymorphism, also known as Dynamic Polymorphism, refers to the type of Polymorphism that happens at the run time. What it means is it can’t be decided by the compiler. Therefore what shape or value has to be taken depends upon the execution. Hence the name Runtime Polymorphism.

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

What is meant by Inheritance?

A

The term “inheritance” means “receiving some quality or behavior from a parent to an offspring.” In object-oriented programming, inheritance is the mechanism by which an object or class (referred to as a child) is created using the definition of another object or class (referred to as a parent). Inheritance not only helps to keep the implementation simpler but also helps to facilitate code reuse

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

What is Abstraction?

A

If you are a user, and you have a problem statement, you don’t want to know how the components of the software work, or how it’s made. You only want to know how the software solves your problem. Abstraction is the method of hiding unnecessary details from the necessary ones. It is one of the main features of OOPs.
For example, consider a car. You only need to know how to run a car, and not how the wires are connected inside it. This is obtained using Abstraction.

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

How much memory does a class occupy?

A

Classes do not consume any memory. They are just a blueprint based on which objects are created. Now when objects are created, they actually initialize the class members and methods and therefore consume memory.

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

Is it always necessary to create objects from class?

A

No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don’t need to be created. You can call the class method directly in this case, using the class name

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

What is a destructor?

A

Contrary to constructors, which initialize objects and specify space for them, Destructors are also special methods. But destructors free up the resources and memory occupied by an object. Destructors are automatically called when an object is being destroyed.

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

Explain Inheritance with an example?

A

Inheritance is one of the major features of object-oriented programming, by which an entity inherits some characteristics and behaviors of some other entity and makes them their own. Inheritance helps to improve and facilitate code reuse.

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

Are there any limitations of Inheritance?

A

Yes, with more powers comes more complications. Inheritance is a very powerful feature in OOPs, but it has some limitations too. Inheritance needs more time to process, as it needs to navigate through multiple classes for its implementation. Also, the classes involved in Inheritance - the base class and the child class, are very tightly coupled together. So if one needs to make some changes, they might need to do nested changes in both classes. Inheritance might be complex for implementation, as well. So if not correctly implemented, this might lead to unexpected errors or incorrect outputs.

17
Q

What are the various types of inheritance?

A
  • Single inheritance
  • Multiple inheritances
  • Multi-level inheritance
  • Hierarchical inheritance
  • Hybrid inheritance
18
Q

What is a subclass?

A

The subclass is a part of Inheritance. The subclass is an entity, which inherits from another class. It is also known as the child class.

19
Q

Define a superclass?

A

Superclass is also a part of Inheritance. The superclass is an entity, which allows subclasses or child classes to inherit from itself.

20
Q

What is an interface?

A

An interface refers to a special type of class, which contains methods, but not their definition. Only the declaration of methods is allowed inside an interface. To use an interface, you cannot create objects. Instead, you need to implement that interface and define the methods for their implementation

21
Q

What is meant by static polymorphism?

A

Static Polymorphism is commonly known as the Compile time polymorphism. Static polymorphism is the feature by which an object is linked with the respective function or operator based on the values during the compile time. Static or Compile time Polymorphism can be achieved through Method overloading or operator overloading.

22
Q

What is meant by dynamic polymorphism?

A

Dynamic Polymorphism or Runtime polymorphism refers to the type of Polymorphism in OOPs, by which the actual implementation of the function is decided during the runtime or execution. The dynamic or runtime polymorphism can be achieved with the help of method overriding

23
Q

What is the difference between overloading and overriding?

A

Overloading is a compile-time polymorphism feature in which an entity has multiple implementations with the same name. For example, Method overloading and Operator overloading.

Whereas Overriding is a runtime polymorphism feature in which an entity has the same name, but its implementation changes during execution. For example, Method overriding.

24
Q

What is an abstract class?

A

An abstract class is a special class containing abstract methods. The significance of abstract class is that the abstract methods inside it are not implemented and only declared. So as a result, when a subclass inherits the abstract class and needs to use its abstract methods, they need to define and implement them

25
Q

How is an abstract class different from an interface?

A

Interface and abstract class both are special types of classes that contain only the methods declaration and not their implementation. But the interface is entirely different from an abstract class. The main difference between the two is that, when an interface is implemented, the subclass must define all its methods and provide its implementation. Whereas when an abstract class is inherited, the subclass does not need to provide the definition of its abstract method, until and unless the subclass is using it.

Also, an abstract class can contain abstract methods as well as non-abstract methods

26
Q

What are access specifiers and what is their significance?

A

Access specifiers, as the name suggests, are a special type of keywords, which are used to control or specify the accessibility of entities like classes, methods, etc. Some of the access specifiers or access modifiers include “private”, “public”, etc. These access specifiers also play a very vital role in achieving Encapsulation - one of the major features of OOPs.

27
Q

What is an exception?

A

An exception can be considered as a special event, which is raised during the execution of a program at runtime, that brings the execution to a halt. The reason for the exception is mainly due to a position in the program, where the user wants to do something for which the program is not specified, like undesirable input