- What is OOPS? Object-Oriented Programming is a programming model or paradigm which revolves around the concept of “OBJECTS”. Objects can be considered as real-world instances of entities like class, that contain some characteristics and behaviors specified in the class template.
Objects are considered the instance of a class, and are therefore sometimes called “instances”. The term “characteristics” refers to the “what” about the Object, and the term “behavior” refers to the “how” about the Object.
With OOPs, the readability, understandability, and maintainability of the code increase multifold.
What are some other programming paradigms other than OOPs?
Imperative Programming Paradigm -
Imperative programming focuses on HOW to execute program logic and defines control flow
Declarative Programming Paradigm -
Declarative programming focuses on WHAT to execute and defines program logic, but not a detailed control flow.
What is meant by Structured Programming?
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.
What are the main features of OOPs?
What is a class?
A class can be understood as a template or a blueprint, which contains some values, known as member data or member, and some set of rules, known as behaviors or functions.
What is an object?
An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template.
What is 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.
- 12. What is Polymorphism? “Poly” which means “many”, and “morph” which means “shapes”.
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 much memory does a class occupy?
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.
- Is it always necessary to create objects from class?
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.
- What is a copy constructor?
Copy Constructor is a type of constructor, whose purpose is to copy an object to another. What it means is that a copy constructor will clone an object and its values, into another object, is provided that both the objects are of the same class.
- What is a destructor?
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.
- What's the difference between a class and a structure?
The structure is saved in the stack memory, whereas the class is saved in the heap memory.
- Are there any limitations of Inheritance?
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.
- What is an interface?
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.
- What is an abstract class?
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
- How is data abstraction accomplished?
Data abstraction is accomplished with the help of abstract methods or abstract classes.
- How is an abstract class different from an interface?
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.
- What is an exception?
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.
- Is it possible to call the base class method without creating an instance?
- If the method is static
- Calling the inherited method inside a derived class
- Calling the method using the base keyword from the sub-classes