OOPS Interview Questions

What is meant by the term OOPs?

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.

What is the need for OOPs?

There are many reasons why OOPs is mostly preferred, but the most important among them are:

  • 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.

What are some major Object Oriented Programming languages?

The programming languages that use and follow the Object-Oriented Programming paradigm or OOPs, are known as Object-Oriented Programming languages. Some of the major Object-Oriented Programming languages include:

  • Java
  • C++
  • Javascript
  • Python
  • PHP

And many more.

You can download a PDF version of Oops Interview Questions.

Download PDF

What are some other programming paradigms other than OOPs?

Programming paradigms refers to the method of classification of programming languages based on their features. There are mainly two types of Programming Paradigms:

  • Imperative Programming Paradigm
  • Declarative Programming Paradigm

Now, these paradigms can be further classified based: 1. Imperative Programming Paradigm: Imperative programming focuses on HOW to execute program logic and defines control flow as statements that change a program state. This can be further classified as: a) Procedural Programming Paradigm: Procedural programming specifies the steps a program must take to reach the desired state, usually read in order from top to bottom. b) Object-Oriented Programming or OOP: Object-oriented programming (OOP) organizes programs as objects, that contain some data and have some behavior. c) Parallel Programming: Parallel programming paradigm breaks a task into subtasks and focuses on executing them simultaneously at the same time. 2. Declarative Programming Paradigm: Declarative programming focuses on WHAT to execute and defines program logic, but not a detailed control flow. Declarative paradigm can be further classified into: a) Logical Programming Paradigm: Logical programming paradigm is based on formal logic, which refers to a set of sentences expressing facts and rules about how to solve a problem b) Functional Programming Paradigm: Functional programming is a programming paradigm where programs are constructed by applying and composing functions. c) Database Programming Paradigm: Database programming model is used to manage data and information structured as fields, records, and files.

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.

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

What are the main features of OOPs?

OOPs or Object Oriented Programming mainly comprises of the below four features, and make sure you don't miss any of these:

  • Inheritance
  • Encapsulation
  • Polymorphism
  • Data Abstraction

What are some advantages of using OOPs?

  • 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.

Why is OOPs so popular?

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.

----

Advanced OOPs Interview Questions

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. So when an object is created, it automatically takes the data and functions that are defined in the class. Therefore the class is basically a template or blueprint for objects. Also one can create as many objects as they want based on a class.

For example, first, a car's template is created. Then multiple units of car are created based on that template.

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. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior. For example, a specific car.

What is encapsulation?

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.

What is Polymorphism?

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.

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

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.

Example:

// In this program, we will see how multiple functions are created with the same name, 
// but the compiler decides which function to call easily at the compile time itself.
class CompileTimePolymorphism{
   // 1st method with name add
   public int add(int x, int y){ 
   return x+y;
   }
   // 2nd method with name add
   public int add(int x, int y, int z){
   return x+y+z;
   }
   // 3rd method with name add
   public int add(double x, int y){ 
   return (int)x+y;
   }
   // 4th method with name add
   public int add(int x, double y){ 
   return x+(int)y;
   }
}
class Test{
   public static void main(String[] args){
   CompileTimePolymorphism demo=new CompileTimePolymorphism();
   // In the below statement, the Compiler looks at the argument types and decides to call method 1
   System.out.println(demo.add(2,3));
   // Similarly, in the below statement, the compiler calls method 2
   System.out.println(demo.add(2,3,4));
   // Similarly, in the below statement, the compiler calls method 3
   System.out.println(demo.add(2,3.4));
   // Similarly, in the below statement, the compiler calls method 4
   System.out.println(demo.add(2.5,3)); 
   }
}

In the above example, there are four versions of add methods. The first method takes two parameters while the second one takes three. For the third and fourth methods, there is a change of order of parameters. The compiler looks at the method signature and decides which method to invoke for a particular method call at compile time. 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.

Example:

class AnyVehicle{
   public void move(){
   System.out.println(“Any vehicle should move!!”);
   }
}
class Bike extends AnyVehicle{
   public void move(){
   System.out.println(“Bike can move too!!”);
   }
}
class Test{
   public static void main(String[] args){
   AnyVehicle vehicle = new Bike();
   // In the above statement, as you can see, the object vehicle is of type AnyVehicle
   // But the output of the below statement will be “Bike can move too!!”, 
   // because the actual implementation of object ‘vehicle' is decided during runtime vehicle.move();
   vehicle = new AnyVehicle();
   // Now, the output of the below statement will be “Any vehicle should move!!”, 
   vehicle.move();
   }
}

As the method to call is determined at runtime, as shown in the above code, this is called runtime polymorphism.

How does C++ support Polymorphism?

C++ is an Object-oriented programming language and it supports Polymorphism as well:

  • Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features like templates, function overloading, and default arguments.
  • Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual functions. Virtual functions take the shape of the functions based on the type of object in reference and are resolved at runtime.

What is meant by Inheritance?

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.

What is Abstraction?

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 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 constructor?

Constructors are special methods whose name is the same as the class name. The constructors serve the special purpose of initializing the objects. For example, suppose there is a class with the name “MyClass”, then when you instantiate this class, you pass the syntax: MyClass myClassObject = new MyClass();

Now here, the method called after “new” keyword - MyClass(), is the constructor of this class. This will help to instantiate the member data and methods and assign them to the object myClassObject.

What are the various types of constructors in C++?

The most common classification of constructors includes:

Default constructor: The default constructor is the constructor which doesn't take any argument. It has no parameters.

class ABC
{
   int x;
      
   ABC()
   {
       x = 0;
   }
}

Parameterized constructor: The constructors that take some arguments are known as parameterized constructors.

 class ABC
{
   int x;
      
   ABC(int y)
   {
       x = y;
   }
}

Copy constructor: A copy constructor is a member function that initializes an object using another object of the same class.

class ABC
{
   int x;
      
   ABC(int y)
   {
       x = y;
   }
   // Copy constructor
   ABC(ABC abc)
   {
       x = abc.x;
   }
}

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.

Are class and structure the same? If not, what's the difference between a class and a structure?

No, class and structure are not the same. Though they appear to be similar, they have differences that make them apart. For example, the structure is saved in the stack memory, whereas the class is saved in the heap memory. Also, Data Abstraction cannot be achieved with the help of structure, but with class, Abstraction is majorly used.

Explain Inheritance with an example?

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.

Let me explain to you with a common example. Let's take three different vehicles - a car, truck, or bus. These three are entirely different from one another with their own specific characteristics and behavior. But. in all three, you will find some common elements, like steering wheel, accelerator, clutch, brakes, etc. Though these elements are used in different vehicles, still they have their own features which are common among all vehicles. This is achieved with inheritance. The car, the truck, and the bus have all inherited the features like steering wheel, accelerator, clutch, brakes, etc, and used them as their own. Due to this, they did not have to create these components from scratch, thereby facilitating code reuse.

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 are the various types of inheritance?

The various types of inheritance include:

  • Single inheritance
  • Multiple inheritances
  • Multi-level inheritance
  • Hierarchical inheritance
  • Hybrid inheritance

What is a subclass?

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.

Define a superclass?

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

29. 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 meant by static polymorphism?

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.

What is meant by dynamic polymorphism?

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.

What is the difference between overloading and overriding?

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.

How is data abstraction accomplished?

Data abstraction is accomplished with the help of abstract methods or abstract classes.

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 an abstract class different from an interface?

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.

What are access specifiers and what is their significance?

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.

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. 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.

What is meant by exception handling?

No one wants its software to fail or crash. Exceptions are the major reason for software failure. The exceptions can be handled in the program beforehand and prevent the execution from stopping. This is known as exception handling. So exception handling is the mechanism for identifying the undesirable states that the program can reach and specifying the desirable outcomes of such states. Try-catch is the most common method used for handling exceptions in the program.

What is meant by Garbage Collection in OOPs world?

Object-oriented programming revolves around entities like objects. Each object consumes memory and there can be multiple objects of a class. So if these objects and their memories are not handled properly, then it might lead to certain memory-related errors and the system might fail.

Garbage collection refers to this mechanism of handling the memory in the program. Through garbage collection, the unwanted memory is freed up by removing the objects that are no longer needed.

Can we run a Java application without implementing the OOPs concept?

No. Java applications are based on Object-oriented programming models or OOPs concept, and hence they cannot be implemented without it.

However, on the other hand, C++ can be implemented without OOPs, as it also supports the C-like structural programming model.

-------------

What is OOPS?

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

Write basic concepts of OOPS?

Following are the concepts of OOPS:

  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

What is a class?

A class is simply a representation of a type of object. It is the blueprint/plan/template that describes the details of an object.

What is an Object?

Advantages and Disadvantages of AWS

An object is an instance of a class. It has its own state, behavior, and identity.

What is Encapsulation?

Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.

Levels are Public, Protected, Private, Internal, and Protected Internal.

What is Polymorphism?

Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

What is Inheritance?

Inheritance is a concept where one class shares the structure and behavior defined in another class. If Inheritance applied to one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

What are manipulators?

Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw.

Explain the term 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 a class name.
  • A constructor must have no return type.

Define Destructor?

A destructor is a method which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.

What is an Inline function?

An inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

What is a virtual function?

A virtual function is a member function of a class, and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.

A virtual function can be declared using a token(virtual) in C++. It can be achieved in C/Python Language by using function pointers or pointers to function.

What is a friend function?

A friend function is a friend of a class that is allowed to access to Public, private, or protected data in that same class. If the function is defined outside the class cannot access such information.

A friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public, or protected.

What is function overloading?

Function overloading is a regular function, but it can perform different tasks. It allows the creation of several methods with the same name which differ from each other by the type of input and output of the function.

Example

1

2

3

4

5

void add(int&amp; a, int&amp; b);

 

void add(double&amp; a, double&amp; b);

 

void add(struct bob&amp; a, struct bob&amp; b);

What is operator overloading?

Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function, and it has its own precedence to execute

What is an abstract class?

An abstract class is a class which cannot be instantiated. Creation of an object is not possible with an abstract class, but it can be inherited. An abstract class can contain only an Abstract method. Java allows only abstract method in abstract class while other languages allow non-abstract method as well.

What is a ternary operator?

The ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types, and it depends on the function. The ternary operator is also called a conditional operator.

What is the use of finalize method?

Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected, and it is accessible only through this class or by a derived class.

What are the different types of arguments?

A parameter is a variable used during the declaration of the function or subroutine, and arguments are passed to the function body, and it should match with the parameter defined. There are two types of Arguments.

  • Call by Value – Value passed will get modified only inside the function, and it returns the same value whatever it is passed into the function.
  • Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.

What is the super keyword?

The super keyword is used to invoke the overridden method, which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass.

It also forwards a call from a constructor, to a constructor in the superclass.

What is method overriding?

Method overriding is a feature that allows a subclass to provide the implementation of a method that overrides in the main class. It will override the implementation in the superclass by providing the same method name, same parameter, and same return type.

What is an interface?

An interface is a collection of an abstract method. If the class implements an interface, it thereby inherits all the abstract methods of an interface.

Java uses Interface to implement multiple inheritances.

What is exception handling?

An exception is an event that occurs during the execution of a program. Exceptions can be of any type – Runtime exception, Error exceptions. Those exceptions are adequately handled through exception handling mechanism like try, catch, and throw keywords.

What are tokens?

A compiler recognizes a token, and it cannot be broken down into component elements. Keywords, identifiers, constants, string literals, and operators are examples of tokens.

Even punctuation characters are also considered as tokens. Example: Brackets, Commas, Braces, and Parentheses.

What is the main difference between overloading and overriding?

Overloading is static Binding, whereas Overriding is dynamic Binding. Overloading is nothing but the same method with different arguments, and it may or may not return the equal value in the same class itself.

Overriding is the same method names with the same arguments and return types associated with the class and its child class.

What is the main difference between a class and an object?

An object is an instance of a class. Objects hold multiple information, but classes don’t have any information. Definition of properties and functions can be done in class and can be used by the object.

A class can have sub-classes, while an object doesn’t have sub-objects.

What is an abstraction?

Abstraction is a useful feature of OOPS, and it shows only the necessary details to the client of an object. Meaning, it shows only required details for an object, not the inner constructors, of an object. Example – When you want to switch on the television, it is not necessary to know the inner circuitry/mechanism needed to switch on the TV. Whatever is required to switch on TV will be shown by using an abstract class.

What are the access modifiers?

Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are five types of access modifiers, and they are as follows:

  • Private
  • Protected
  • Public
  • Friend
  • Protected Friend

What are sealed modifiers?

Sealed modifiers are the access modifiers where the methods can not inherit it. Sealed modifiers can also be applied to properties, events, and methods. This modifier cannot be used to static members.

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 “Static method.”

Doing Inheritance from that class.-Use Base Keyword from a derived class.

What is the difference between new and override?

The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

What are the various types of constructors?

There are three types of constructors:

–  Default Constructor – With no parameters.

–  Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.

–  Copy Constructor – Which creates a new object as a copy of an existing object.

What is early and late Binding?

Early binding refers to the assignment of values to variables during design time, whereas late Binding refers to the assignment of values to variables during run time.

What is ‘this’ pointer?

THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which differentiates between the current object with the global object. It refers to the current object.

What is the difference between structure and a class?

The default access type of a Structure is public, but class access type is private. A structure is used for grouping data, whereas a class can be used for grouping data and methods. Structures are exclusively used for data, and it doesn’t require strict validation, but classes are used to encapsulate and inherent data, which requires strict validation.

What is the default access modifier in a class?

The default access modifier of a class is Internal and the default access modifier of a class member is Private.

What is a pure virtual function?

A pure virtual function is a function which can be overridden in the derived class but cannot be defined. A virtual function can be declared as Pure by using the operator =0.

Example –

 

1

2

3

Virtual void function1() // Virtual, Not pure

 

Virtual void function2() = 0 //Pure virtual

What are all the operators that cannot be overloaded?

Following are the operators that cannot be overloaded -.

  1. Scope Resolution (::)
  2. Member Selection (.)
  3. Member selection through a pointer to function (.*)

What is dynamic or run time polymorphism?

Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name, same signature but with different implementation.

Do we require a parameter for constructors?

No, we do not require a parameter for constructors.

What is a copy constructor?

This is a special constructor for creating a new object as a copy of an existing object. There will always be only one copy constructor that can be either defined by the user or the system.

What does the keyword virtual represented in the method definition?

It means we can override the method.

Whether static method can use nonstatic members?

False.

What are a base class, subclass, and superclass?

The base class is the most generalized class, and it is said to be a root class.

A Subclass is a class that inherits from one or more base classes.

The superclass is the parent class from which another class inherits.

What is static and dynamic Binding?

Binding is nothing but the association of a name with the class. Static Binding is a binding in which name can be associated with the class during compilation time, and it is also called as early Binding.

Dynamic Binding is a binding in which name can be associated with the class during execution time, and it is also called as Late Binding.

How many instances can be created for an abstract class?

Zero instances will be created for an abstract class. In other words, you cannot create an instance of an Abstract Class.

Which keyword can be used for overloading?

Operator keyword is used for overloading.

What is the default access specifier in a class definition?

Private access specifier is used in a class definition.

Which OOPS concept is used as a reuse mechanism?

Inheritance is the OOPS concept that can be used as a reuse mechanism.

Which OOPS concept exposes only the necessary information to the calling functions?

Encapsulation

---------------

Can you explain the different types of Inheritance?

There are four main types of Inheritance in OOPS as listed below:

  • Single Inheritance: This includes one base class along with one derived class.
  • Hierarchical Inheritance: This inheritance class includes one base class as well as multiple derived classes of the same base class.
  • Multilevel Inheritance: This includes a class derived from a derived class.
  • Multiple Inheritance: This class includes several base classes as well as a derived class.

Explain the concept of a hashtable.

Hashtable is used to store multiple items. Each of these items is linked with their own unique string key and can be accessed using the key associated with it.

What is Association?

Association can be described as a relationship that exists between two objects with multiplicity.

Can you touch upon the core concepts of OOPS?

The core concepts of OOPS are as below:

  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction
  • Composition
  • Association
  • Aggregation

Can you list out some examples of tokens?

Here are some common examples of tokens:

  • Keywords
  • Commas
  • Constants
  • Identifiers
  • Brackets
  • Operators

Can you describe Polymorphism and list out the different types of Polymorphism?

Polymorphism can be termed as the ability to take on more than one form. In OOPS, Polymorphism means a single interface with multiple implementations for a certain class of action.

Polymorphism can further be classified into two distinct types:

  • Static
  • Dynamic

Can you explain what Access Modifiers are?

Access modifiers are used to figure out the scope of the method or variables accessible from other various objects or classes.

Access modifiers can be of five types:

  • Private
  • Public
  • Protected
  • Friend
  • Protected Friend

Can you list out the different types of constructors?

Constructors are of three types as listed below:

Default Constructor: Contains no parameters.

  • Parametric Constructor: Contains parameters. This parameter is used to create a new class instance and for simultaneously passing arguments.
  • Copy Constructor: This is used to create a new object as a copy of an existing object.

In addition to the above-mentioned questions, here’s an additional list of 8 frequently asked OOPS Interview questions that will surely assist you in your bid to crack your all-important OOPS interview.

  • a. Can you explain what a multicast Delegate is?
  • b. Please describe the friend function.
  • c. Explain the what Information Hiding is in OOPS.
  • d. Explain the concepts of Overloading and Overriding Polymorphism.
  • e. Describe the concept of Enum?
  • f. Explain multiple inheritance.
  • g. Can you point out the differences between Shadowing and Overriding?
  • h. Touch upon the differences between Static and Dynamic polymorphism.

----------------

What Is Oops?

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

Write Basic Concepts Of Oops?

Following are the concepts of OOPS and are as follows:.

  • 1.Abstraction.
  • 2.Encapsulation.
  • 3.Inheritance.
  • 4.Polymorphism.

What Is A Class?

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.

What Is An Object?

Object is termed as an instance of a class, and it has its own state, behavior and identity.

What Is Encapsulation?

Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.

Levels are Public,Protected, Private, Internal and Protected Internal.

What Is Polymorphism?

Polymorphism is nothing butassigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

What Is Inheritance?

Inheritance is a concept where one class shares the structure and behavior defined in another class. Ifinheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

What Are Manipulators?

Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw.

Define A Constructor?

Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Rules forconstructor are:.

  • Constructor Name should be same as class name.
  • Constructor must have no return type.

Define Destructor?

Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name.

What Is Inline Function?

Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

What Is A Virtual Function?

Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.

Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.

What Is Friend Function?

Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information. Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.

What Is Function Overloading?

Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allowscreation of several methods with the same name which differ from each other by type of input and output of the function.

	void add(int& a, int& b);

	void add(double& a, double& b);

	void add(struct bob& a, struct bob& b);

What Is Operator Overloading?

Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute.

	class complex { 

	double real, 

	imag; public: complex(double r, double i) : real(r), 

	imag(i) {} complex operator+(complex a, complex b); 

	complex operator*(complex a, complex b); 

	complex& operator=(complex a, complex b);

	}

	a=1.2, b=6

What Is An Abstract Class?

An abstract class is a class which cannot be instantiated. Creation of an object is not possible with abstract class , but it can be inherited. An abstract class can contain only Abstract method. Java allows only abstract method in abstract class while for other language it allows non-abstract method as well.

What Is A Ternary Operator?

Ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types , and it is depends on the function. Ternary operator is also called asconditional operator.

What Is The Use Of Finalize Method?

Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected , and it is accessible only through this class or by a derived class.

What Are Different Types Of Arguments?

A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function , and it should match with the parameter defined. There are two types of Arguments. Call by Value – Value passed will get modified only inside the function , and it returns the same value whatever it is passed it into the function. Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.

What Is Super Keyword?

Super keyword is used to invoke overridden method which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass. It also forwards a call from a constructor to a constructor in the superclass.

What Is Method Overriding?

Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the superclass by providing the same method name, same parameter and same return type.

What Is An Interface?

An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

What Is Exception Handling?

Exception is an event that occurs during the execution of a program. Exceptions can be of any type – Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.

What Are Tokens?

Token is recognized by a compiler and it cannot be broken down into component elements. Keywords, identifiers, constants, string literals and operators are examples of tokens. Even punctuation characters are also considered as tokens – Brackets, Commas, Braces and Parentheses.

Difference Between Overloading And Overriding?

Overloading is static binding whereas Overriding is dynamic binding. Overloading is nothing but the same method with different arguments , and it may or may not return the same value in the same class itself.

Overriding is the same method names with same arguments and return types associates with the class and its child class.

Difference Between Class And An Object?

An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object.Class can have sub-classes, and an object doesn’t have sub-objects.

What Is An Abstraction?

Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object. Means, it shows only necessary details for an object, not the inner details of an object. Example – When you want to switch On television, it not necessary to show all the functions of TV. Whatever is required to switch on TV will be showed by using abstract class.

What Are Access Modifiers?

Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are 5 types of access modifiers , and they are as follows:.

  • Private.
  • Protected.
  • Public.
  • Friend.
  • Protected Friend.

What Is Sealed Modifiers?

Sealed modifiers are the access modifiers where it cannot be inherited by the methods. Sealed modifiers can also be applied to properties, events and methods. This modifier cannot be applied to static members.

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,.Static method.Doing inheritance from that class.-Use Base Keyword from derived class.

What Is The Difference Between New And Override?

The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

What Are The Various Types Of Constructors?

There are three various types of constructors , and they are as follows:.

  • Default Constructor – With no parameters.
  • Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.
  • Copy Constructor – Which creates a new object as a copy of an existing object.

What Is Early And Late Binding?

Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.

What Is ‘this’ Pointer?

THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which differentiates between the current object with the global object. Basically, it refers to the current object.

What Is The Difference Between Structure And A Class?

Structure default access type is public , but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods. Structures are exclusively used for dataand it doesn’t require strict validation , but classes are used to encapsulates and inherit data which requires strict validation.

What Is The Default Access Modifier In A Class?

The default access modifier of a class is Private by default.

What Is Pure Virtual Function?

A pure virtual function is a function which can be overridden in the derived classbut cannot be defined. A virtual function can be declared as Pure by using the operator =0.

	Virtual void function1() // Virtual, Not pure

	Virtual void function2() = 0 //Pure virtual

What Are All The Operators That Cannot Be Overloaded?

Following are the operators that cannot be overloaded -.

  • 1.Scope Resolution (:: )
  • 2.Member Selection (.)
  • 3.Member selection through a pointer to function (.*)

What Is Dynamic Or Run Time Polymorphism?

Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name,same signature but with different implementation.

Do We Require Parameter For Constructors?

No, we do not require parameter for constructors.

What Is A Copy Constructor?

This is a special constructor for creating a new object as a copy of an existing object. There will be always only on copy constructor that can be either defined by the user or the system.

What Does The Keyword Virtual Represented In The Method Definition?

It means, we can override the method.

What Are Base Class, Sub Class And Super Class?

  • Base class is the most generalized class , and it is said to be a root class.
  • Sub class is a class that inherits from one or more base classes.
  • Super class is the parent class from which another class inherits.

What Is Static And Dynamic Binding?

Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time , and it is also called as early Binding. Dynamic binding is a binding in which name can be associated with the class during execution time , and it is also called as Late Binding.

How Many Instances Can Be Created For An Abstract Class?

Zero instances will be created for an abstract class.

Which Keyword Can Be Used For Overloading?

Operator keyword is used for overloading.

What Is The Default Access Specifier In A Class Definition?

Private access specifier is used in a class definition.

Which Oops Concept Is Used As Reuse Mechanism?

Inheritance is the OOPS concept that can be used as reuse mechanism.

Which Oops Concept Exposes Only Necessary Information To The Calling Functions?

Data Hiding / Abstraction

What Are The Types Of Constructors?

Basically constructors are 5 types those are

  1. Default Constructor
  2. Parameterized Constructor
  3. Copy Constructor
  4. Static Constructor
  5. Private Constructor
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +