Skip to content

50 OOPS Interview Questions asked in SRM Placements

    1. Table of Contents

      What is OOPs?

    Programmers can use objects to represent real-world circumstances thanks to object-oriented programming. Any entity with states and behaviours is an object. While methods define an item's behaviours, states reflect the characteristics or data of an entity. Objects include students, workers, books, etc. By exchanging messages, these things communicate with one another. A class is also a template for building an object. A class is required in order to generate objects. For instance, there needs to be an Employee class in order to generate an Employee object.

    1. Difference between Procedural programming and OOPs?

    Procedural Programming

    Oops

    Procedural Programming is based on functions.

    Object-oriented programming is based on real-world objects.

    It shows the data to the entire program.

    It encapsulates the data.

    It does not have a scope for code reuse.

    It provides more scope for code reuse.

    It follows the concept of top-down programming.

    It follows a bottom-up programming paradigm.

    The nature of the language is complicated.

    It is less complicated in nature, so it is easier to modify, extend and maintain.

    It is hard to modify, extend and maintain the code.

     

     

    1. Why use OOPs?

    Programming with OOP lets you package together data states and functionality to change those data states while keeping the specifics secret (Consider the analogy of a car, you can only see the steering of the car while driving, the circuitry behind it is hidden from you). As a result, OOP design produces flexible, modular, and abstract code. Because of this, it is very helpful for developing larger programs. Using classes and objects, you may include OOP into your code. The objects you construct will have the states and capabilities of the class to which they belong.

    1. What are the basic concepts of OOPs?

    The basic concepts of OOPs are:

    • Inheritance
    • Encapsulation
    • Polymorphism
    • Abstraction
    1. What is Encapsulation?

    Encapsulation is also a part of the OOPs concept. It refers to the bundling of data with the methods that operate on that data. It also helps to restrict any direct access to some of an object's components.

    1. What is Abstraction?

    Abstraction is an OOPs concept to build the structure of real-world objects. It "shows" only essential attributes and "hides" unnecessary information from the outside. The main focus of abstraction is to hide unnecessary details from the users. It is one of the most important concepts of OOPs.

    1. What is method overloading?

    There is a concept where two or more methods can have the same name. But they should have different parameters, different numbers of parameters, different types, or both. These methods are known as overloaded methods and this feature is called method overloading

    1. What is method overriding?

    Method overriding is a concept of object-oriented programming.

    It is a language feature that allows a subclass or child class to provide a specific implementation of a method which is already provided by one of its superclasses or parent classes.

    1. Types of Inheritance in OOPS

    Different types of inheritances in OOps are as follows:

    • Single Inheritance
    • Multiple Inheritance
    • Multi-level Inheritance
    • Multi-path Inheritance
    • Hierarchical Inheritance
    • Hybrid Inheritance

    Become a member and get full access of SRM PLACEMENT Assests.

    1. What are the main features of OOPs?

    The main features of OOPs are given as follows:

    • In OOP, you combine the code into one unit so you can specify the parameters of each piece of data. This process of wrapping up data into a single unit is called encapsulation. 
    • By using classes, you can generalise your object types and make your application easier to use. This is termed as an abstraction.
    • The ability for a class to inherit characteristics and behaviours from another class allows for more code reuse.
    • Polymorphism allows for the creation of several objects from a single, adaptable class of code.
    1. Is it possible to call the base class method without creating an instance?

    Yes, we can possibly call the base class method without creating an instance in the following 3 cases:

    1. If the method is static
    2. Calling the inherited method inside a derived class
    3. Calling the method using the base keyword from the sub-classes

    The most popular case is that of the static methods.

    1. What are the limitations of OOPs?

    Following are some of the common limitations of OOPs:

    • Size exceeds that of other programs.
    • It took a lot of work to make, and it runs more slowly than other programs.
    • It is inappropriate for certain types of issues.
    • It takes some getting used to.
    1. What are constructors?

    The constructor has the same name as the class.
    A constructor is also a special kind of method. It is used to initialize objects of the class.

    1. Types of constructor

    Types of constructors depend upon languages

    • Private Constructor
    • Default Constructor
    • Copy Constructor
    • Static Constructor
    • Parameterized Constructor
    1. What is the difference between a class and a structure?

    Class: Class is basically a User-defined blueprint from which objects are created. It consists of methods ( set of instructions) that are performed on the objects.

    Structure: A structure is also a user-defined collection of variables. Structures are also different data types.

    A user-defined class serves layout or blueprint from which objects can be built. In essence, a class is made up of fields known as attributes and methods known as member functions that define actions. A structure is a grouping of variables of various data kinds under one heading.

    1. What are the access modifiers?

    Access modifiers or access specifiers are the keywords in object-oriented languages.  It helps to set the accessibility of classesmethods, and other members.

    1. What languages come under the oops concept?

    Simula is known as the first object-oriented programming language, the most popular OOP languages are:

    • Java
    • JavaScript
    • Python
    • C++
    • Visual Basic
    • .NET
    • Ruby
    • Scala
    • PHP
    1. What is inheritance?

    Whenever one class is derived from another, it is referred to as inheritance. The child class will inherit all of the parent class's public and protected properties and methods. Apart from the attributes and methods inherited from the parent class, it can also have its own additional set of features. The' extends' keyword is used to specify an inherited class.

    If you derive a  class from another class that is known as inheritance. The child class will inherit all the public and protected properties and methods from the parent class. The child class can also have its own properties and methods. An inherited class is defined by using the extends keyword.

    1. What is hybrid inheritance?

    The type of inheritance formed by the combination of different types of inheritances like single, multiple inheritances, etc. is classified as hybrid inheritance.

    1. What is hierarchical inheritance?

    In the case of a hierarchical inheritance, multiple subclasses inherit from a parent class. Hierarchical inheritance is a type of inheritance in which multiple classes are descended from a single parent or base class. For example, the fruit class can have 'apple', 'mango', 'banana', 'cherry' etc. as its subclasses.

    Become a member and get full access of SRM PLACEMENT Assests.

    1. What are the limitations of inheritance?

    It Increases the execution time and effort. It also requires jumping back and forth between different classes. The parent class and the child class are always tightly coupled. Afford modifications in the program would require changes for the parent and the child's class. Inheritance requires careful implementation otherwise it would lead to incorrect results.

    1. What is a superclass?

    A superclass is a class from which a subclass or child class is derived. Base class and parent class are other names for a superclass. For example, if Student is a class derived from the Person class, then the Person class will be referred to as the superclass.

    A superclass or base class is also a class that works as a parent to some other class/ classes.

    For example, the Vehicle class is a superclass of class Bike.

    1. What is a subclass?

    A class that derives from another class is referred to as a subclass. A subclass inherits the properties of its ancestors or parent classes. For example, the class Bike is a subclass or a derivative of the Vehicle class.

    1. What is Polymorphism?

    Polymorphism is one of the most used and core concepts in OOP languages. It explains the concept of different classes can be used with the same interface. Each of these classes can have its own implementation of the interface. 

    1. What is static polymorphism?

    In OOP, static polymorphism determines which method to call at compile time. For the same trigger with static polymorphism, the object might respond differently. Function, constructor and operator overloading are examples of static polymorphism.

    1. What is dynamic polymorphism?

    Dynamic polymorphism is a method or process that handles a call to an overridden method during runtime rather than at compile time. It is also referred to as dynamic method dispatch or runtime polymorphism. Using method overriding, we can create dynamic polymorphism. An example of runtime polymorphism: is method overriding.

    1. What is operator overloading?

    The user-defined data type is given a special meaning by the operator using operator overloading. It is a compile-time polymorphism.

    1. Differentiate between overloading and overriding.

    When two or more methods in the same class have the same name but different parameters, this is referred to as overloading. The technique of using the same method signature, i.e., name and parameters, in both the superclass and the child class is known as overriding.

    1. What is encapsulation?

    Encapsulation is used to wrap the data and the code which works in a single unit together. Example: Encapsulation allows data-hiding as the data specified in one class is hidden from other classes.

    1. What is the difference between public, private and protected access modifiers?

    In object-oriented programming languages, access modifiers are used to specify the visibility and accessibility of class members (fields, methods, and constructors). There are three types of access modifiers:

    1. Public: Members marked as public can be accessed from anywhere within the program.

    2. Private: Members marked as private can only be accessed within the class in which they are declared. They are not accessible from outside the class.

    3. Protected: Members marked as protected can be accessed within the class in which they are declared and also from subclasses (classes that inherit from the class in which the protected members are declared).

    In general, it is a good practice to make data members private and provide public methods to access and modify them. This is known as the principle of encapsulation, which helps to protect the internal state of the object and promotes modularity, reusability, and maintainability of code.

    Become a member and get full access of SRM PLACEMENT Assests.

    1. What is data abstraction?

    Data abstraction is one of the most important features of OOPs. It only allows important information to be displayed. It helps to hide the implementation details.

    For example, while using a mobile, you know, how can you message or call someone but you don't know how it actually happens.

    This is data abstraction as the implementation details are hidden from the user.

    1. How to achieve data abstraction?

    Data abstraction can be achieved using two ways:

    • Abstract class
    • Abstract method
    1. What is an abstract class?

    An abstract class is also a class which is consists of abstract methods.

    So what is an abstract method?

    These methods are basically declared but not defined and If these methods need to be used later in some subclass that time those methods have to be exclusively defined in the subclass.

    1. Differentiate between data abstraction and encapsulation.

    Data abstraction refers to the process of providing a simplified view of data to the user, without exposing the underlying implementation details. It involves separating the essential characteristics of data from the implementation details, so that the user can focus on the essential features without being overwhelmed by the implementation details.

    Encapsulation, on the other hand, refers to the process of bundling data and functions that operate on that data within a single unit, or object. In other words, it involves wrapping up of data and functions into a single unit, which can be accessed and modified only through a well-defined interface.

    In summary, data abstraction deals with providing a simplified view of data, while encapsulation deals with bundling data and functions into a single unit. Both data abstraction and encapsulation are important concepts in object-oriented programming, and are used to promote modularity, reusability, and maintainability of code.

    1. What are virtual functions?

    Virtual functions are also part of the functions which are present in the parent class and they are overridden by the subclass. These functions help to achieve runtime polymorphism.

    1. What is a destructor?

    A destructor is a method that is called automatically when an object is destroyed.

    The destructor also recovers the heap space which was allocated to the destroyed object. It also start closing the files and database connections of the object, etc.

    1. What is a copy constructor?

    By copying the members of an existing object, the copy constructor initialises the members of a newly formed object. The argument for the copy constructor is a reference to an object of the same class. Programmers have the option of directly defining the copy constructor. The compiler defines the copy constructor if the programmer doesn't.

    1. What is the use of 'finalize'?

    Finalize is used to free the unmanaged resources and also help to clean before Garbage Collection(GC). It performs memory management tasks.

    1. What is Garbage Collection(GC)?

    Programming languages like C# and Java include garbage collection (GC) as a memory recovery mechanism. A programming language that supports garbage collection (GC) contains one or more GC engines that automatically release memory space that has been reserved for things the application is no longer using.

    1. What is a final variable?

    A final variable can only receive one explicit initialization. A reference variable that has been marked as final is unchangeable in its object reference. The data included in the object, however, can be modified. As a result, while the object's state can be altered, its reference cannot.

    1. What is an exception?

    An exception is a kind of message that interrupts and comes up when there is an issue with the normal execution of a program. Exceptions provide an error and transfer it to the exception handler to resolve it. The state of the program is saved as soon as an exception is raised.

    1. What is exception handling?

    Exception handling in Object-Oriented Programming is the most important concept. It is used to manage errors. An exception handler help to throw errors and then catch the error in order to solve them.

    1. What is the difference between an error and an exception?

    2. What is a try/ catch block?

    The terms "try" and "catch" describe how to handle exceptions brought on by coding or data mistakes while a program is running. The section of code where exceptions occur is called a try block. Exceptions from try blocks are caught and handled in a catch block.

    1. What is a finally block?

    Finally designates the section of code that works with the try keyword. It specifies code that is always executed before the method is finished, immediately behind the try and any catch blocks. Regardless of whether an exception is thrown or caught, the finally block is always executed.

    1. Can you call the base class method without creating an instance?

    Yes, you are allowed to call the base class without instantiating it but there are some conditions that are applicable:

    • If it is a static method
    • The base class is inherited by some other subclass
    1. What is the difference between OOP and SOP?

    The key distinction between structured and object-oriented programming is that the former allows for the creation of programs using a collection of modules or functions, whilst the latter allows for the construction of programs using a collection of objects and their interactions.

    Object-oriented programming involves concepts of objects and classes. Everything is considered as an object which has specific properties and behaviours which are represented in a class. Object-oriented programming provides encapsulation and abstraction in the code. Ex: – Java Programming language.

    Structure-oriented programming involves the concepts of functions and structures. Everything is considered functionality and structures, represented using functions—Ex: – C Programming language.

    1. What is the difference between a class and an object?

    Any real-world entity is called an object. The object has specific properties and behaviours, and the similar type of objects having similar features and behaviours are grouped as a class. Hence, Class is a blueprint of objects, and an object is an instance of a class.

    Ex: –  

    1. An Animal is a class, and cat, dog, etc., are objects with common properties like name, type, and common behaviors like speaking, walking, running, etc.
    1. Mobile is a class, and Nokia, moto, iPhone, etc., are objects with common properties like modal_no, color, etc., and common behaviors like audio_calling, video_calling, music, etc.

      49.What are 'access specifiers'?

    Access specifiers are the keywords in any programming language used to specify the Class's, method's, interface's and variable's behaviour concerning its accessibility. The access specifiers in C++ Programming are public, private, and protected.

    1. Can you create an instance of an abstract class?

    No, an instance of the Abstract class cannot be created. To implement the abstract Class, abstract methods, the Abstract Class should be extended by another class, and the object of the implementation class can be created.

    Become a member and get full access of SRM PLACEMENT Assests.

    Leave a Reply