OOPS Interview Questions and Answers For Freshers
OOPS Interview Questions and Answers for freshers
Below you will get the OOPS Interview Questions and Answers for Freshers.
You will get OOPS questions that are asked in the interview on this page.
This will help you in preparing for the Interview, and you will also get an idea of how to prepare.
OOPS is a programming concept that works on the principles of abstraction, encapsulation, inheritance, and polymorphism.
What is OOPS Concept?
Object-oriented programming (OOP) is a programming paradigm that organizes software architecture around files, rather than functions and logic. An object is a data field with its own set of attributes and actions.
It enables users to build the objects they desire and then write methods to manage them. The fundamental idea behind OOPs is to make objects and then reuse them throughout the program, and manipulate these objects to get results.
There are four pillars of Object-Oriented Programming concept and they pretty much run the OOPS concept in C++ –
OOPS Interview Questions and Answers For Freshers
1. What is a class?
A class is nothing more than a description of an object. It is a model, design, or prototype that describes an object’s features.
2. What is an object?
An object is termed as an instance of a class, and it has its own state, behavior, and identity.
3. Define a constructor?
A constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.
Rules for constructor are:
- Constructor Name should be the same as the class name.
- A constructor must have no return type.
4. What is the difference between multiple and multilevel inheritance?
- Multiple inheritance comes into the picture when a class inherits more than one base class.
- Example: A class defining a child inherits from two base classes Mother and Father.
- Multilevel inheritance means a class inherits from another class which itself is a subclass of some other base class.
- Example: A class describing a sports car will inherit from a base class Car which inturn inherits another class Vehicle
5. What is a superclass?
A superclass or base class is a class that acts as a parent to some other class or classes.
For example, the Vehicle class is a superclass of Class Car.
or, BMW is a type of car, so the superclass for BMW is Class Car.
6. Differentiate between overloading and overriding.
- Two or more methods having the same name but different parameters or signatures.
- Resolved during compile-time.
- Child class redefining methods present in the base class or parent class with the same parameters/signatures.
- Resolved during run-time.
7. What is the use of ‘finalize’?
Finalize is a method used to free up unmanaged resources and cleanup before Garbage Collection(GC).
It performs memory management tasks.
8. What is a try/ catch block?
A try/ catch block is used to handle exceptions.
The try block defines a set of statements that may lead to an error. The catch block basically catches the exception.
9. What is exception handling?
Exception handling in Object-Oriented Programming is a very important concept that is used to manage errors.
An exception handler allows errors to be thrown and caught and implements a centralized mechanism to resolve them.
10. What is Encapsulation?
Encapsulation is a feature of an entity that holds all secret data.
The members of that class can only see the hidden details.
Public, Protected, Private are the different levels.
11. What is Inheritance? Explain the use of Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined in another class. Inheritance applied to one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
- For Method Overriding (so runtime polymorphism can be achieved).
- For Code Reusability.
12. What are Static Binding and Dynamic Binding?
- Static Binding is a binding in which the name can be combined with the class during collection time, and it is also called early binding.
- Dynamic Binding is a binding in which name can be identified with the class during execution time, and it is also known as Late Binding.
13. Can you call the base class method without creating an instance?
Yes, you can call the base class without instantiating it if :
- It is a static method.
- The base class is inherited by some other subclass.
14. How Can We Call The Base Method Without Creating An Instance?
Yes, it is possible to call the base method without creating an instance.
And that method should be the static method. Doing inheritance from that class use the Base Keyword from a derived class.
15. What are the differences between method and constructor?
- Constructors’ name should match with that of Class.
- They are used to create, initialize and allocate memory to the object.
- Constructors are implicitly invoked by the system whenever objects are created.
- They are invoked using new keyword while creating an instance of the class (object).
- A constructor does not have a return type.
- Constructors cannot be inherited by the subclass.
- Methods should not have the same name as the class name.
- Methods are used to execute certain statements written inside them.
- Methods are invoked when it is called.
- Methods are invoked during program execution.
- Method has a return type.
- Methods can be inherited by a sub-class.
16. Explain the difference between abstract class and method?
- An object cannot be created from the abstract class.
- Subclass created or inherit abstract class to access members of the abstract class.
- An abstract class can contain abstract methods or non-abstract methods.
- An abstract method has a signature but does not have a body.
- It is compulsory to override abstract methods of the superclass in their sub-class.
- Class containing abstract method should be made abstract class.
17. What is the difference between extends and implements?
- A class can extend another class (child extending parent by inheriting his characteristics). Interface as well inherit (using keyword extends) another interface.
- A subclass extending superclass may not override all of the superclass methods
- A class can only extend a single superclass.
- An interface can extend more than one interfaces.
- Syntax: Class Child extends Class Parent
- A class can implement an interface
- Class implementing interface has to implement all the methods of the interface.
- A class can implement any number of interfaces.
- An interface cannot implement any other interface.
- Syntax: Class Hybrid implements Rose
18. What is a need for Object-oriented programming?
For more protection and control over data access, OOP offers access specifiers and data hiding functionality, overloading can be performed through function and operator overloading, and Code Reuse is possible because artifacts generated in one program can be reused in another programs.
Data redundancy, code maintenance, data protection, and the use of terms like encapsulation, abstraction, polymorphism, and inheritance are all important considerations.
19. What are the various types of constructors?
There are three types of constructors:
- Default Constructor – With no parameters.
- Parametric Constructor – These constructors are those having parameters. Create a new instance of a class and also pass arguments simultaneously.
- Copy Constructor – This creates a new object as a copy of an existing object.