preloader
OOPS Interview Questions

Top 50 OOPS Interview Questions and Answers for 2022 Job Interview

author image

OOPS is one of the most important programming languages and is very much in demand by many big companies. So freshers and experienced who are appearing for upcoming OOPS job interviews can prepare from these OOPS Interview Questions. Here we have brought you 50+ OOPS Interview questions and answers for 2, 3, 5, 7, 10 years experienced candidates to clear the job interview.

About OOPS: Object-Oriented Programming (OOPs) is a programming language that is based on objects than functions and methods. Individual objects are grouped into classes. OOPs, execute real-world entities like polymorphism, inheritance, hiding, etc. into coding. It also enables binding data and code together.

.NET Interview Questions

1. What is OOP?

2. Name some widely used OOP languages.

3. Tell the purpose of OOPs concepts?

4. Name the four core features of OOPs?

5. Why do we use OOPS?

6. Can you call the base class technique without making an instance?

7. Why OOP is so famous?

8. Name various types of inheritance?

9. Explain hybrid inheritance?

10. Explain hierarchical inheritance?

11. Tell some limitations of inheritance?

12. Explain a superclass?

13. Tell some advantages and disadvantages of OOP?

14. Tell some limitations of OOPs?

15. Explain pure object-oriented language?

16. Why Java is not considered a pure object-oriented programming language?

17. Explain class and object?

18. Explain the concept of access specifiers?

19. Explain encapsulation?

20. Explain manipulators and their work in OOP?

21. Tell the rules for forming a constructor?

22. Tell some characteristics of an abstract class?

23. Can a class inherit the constructor of its base class?

24. Explain composition?

25. Explain the main benefits of composition?

26. Differentiate Composition and Inheritance?

27. What is constructor chaining?

28. Explain Coupling in OOP?

29. Tell the names of operators that can’t be overloaded.

30. Differentiate new and override modifiers?

31. What do you understand by overloading and overriding, show with example?

32. What is Cohesion in OOP?

33. Explain types of Cohesion in OOP:

34. Differentiate a base class and a superclass?

35. Explain data abstraction and how can we achieve it?

36. Explain the different levels of data abstraction?

37. Explain the different types of variables in OOP?

38. Can we overload a constructor?

39. Is it possible to overload the main() method in Java?

40. Tell some real-world examples of polymorphism?

41. Is it possible to create an instance of an abstract class?

42. Explain an interface?

43. Explain virtual functions?

44. Explain pure virtual functions?

45. Explain constructor?

46. Explain destructor?

47. Name different types of constructors in OOPS

48. Explain a copy constructor?

49. Tell the use of ‘finalize’?

50. Explain Garbage Collection (GC)?


Learn More Interview Questions Here:


.NET Interview Questions And Answers

1. What is OOP?

OOP means object-oriented programming. It is a programming model that spins around the object instead of function and technique. In simple words, it is a method for creating applications that highlight objects. An object is a genuine word entity that includes data and code. It permits binding data and code together.

2. Name some widely used OOP languages.

Some of the widely used OOP languages are: Python Go Java Ruby Dart C# C++

3. Tell the purpose of OOPs concepts?

OOP aims to execute real-world entities such as inheritance, polymorphism, hiding in programming. The core purpose of OOP is to attach the data and the functions that work on them so that no other part of the code can use this data except that function.

4. Name the four core features of OOPs?

Data Abstraction Inheritance Polymorphism Encapsulation

5. Why do we use OOPS?

OOPS authorizes clarity in programming thus authorizing simplicity in solving difficult problems Code can be reutilized via inheritance thus reducing redundancy Data and code are attached together by encapsulation OOPs permits data hiding, so, private data is kept hidden Problems can be split into different parts that make it simple to solve The concept of polymorphism provides flexibility to the program by permitting the entities to have considerable forms

6. Can you call the base class technique without making an instance?

Yes, you can call the base class technique without instantiating it if: It is a static method The base class is inherited by another subclass

7. Why OOP is so famous?

OOPs, the programming model is one of the best styles of programming. It assists in writing a complicated piece of code easily and also permits the users to manage and maintain them. Some of the main features of OOPs are Data Abstraction, Inheritance, Encapsulation, and Polymorphism that make it easy for developers to decode complex designs.

8. Name various types of inheritance?

Single inheritance Multiple inheritance Multilevel inheritance Hierarchical inheritance Hybrid inheritance

9. Explain hybrid inheritance?

It is a mixture of multiple and multi-level inheritances.

10. Explain hierarchical inheritance?

Hierarchical inheritance guides to inheritance where a single base class has more than one subclasses.

11. Tell some limitations of inheritance?

Inheritance increases the time and effort needed to perform a program as it needs jumping to and fro between different classes. Parent and child class get strongly coupled. Any changes to the program would need modifications both in the parent as well as the child’s class. Requires careful execution else would lead to inaccurate results.

12. Explain a superclass?

A superclass or base class is a class that performs as a parent to another class or classes.

13. Tell some advantages and disadvantages of OOP?

Advantages of OOP It pursues a bottom-up approach. It presents the real world well. It permits us the reusability of code. Avoids unwanted data exposure to the user by using the abstraction. OOP pushes the developers to have a long and vast design phase that results in more useful design and lesser flaws. Decompose a complicated problem into fewer chunks. The programmer can reach their objectives faster. Reduces the complexity. Disadvantages of OOP Proper planning is needed. Program design is tough. The developer should be well-skilled. Classes tend to be too generalized.

14. Tell some limitations of OOPs?

It needs intensive testing processes. Decoding problems takes more time than Procedure Oriented Programming. The size of the code is larger than the programs written using the procedure-oriented programming approach. Software created using this approach needs a substantial amount of pre-work and planning. OOP code is complex to comprehend if you don’t have the corresponding class documentation. In some scenarios, these codes can consume a large amount of memory. Not fit for small problems. Takes more time to decode problems.

15. Explain pure object-oriented language?

A programming language that treats everything inside the program as an object is called pure object-oriented language. The elementary types are not supported by the pure OOPs language. Some additional features that must satisfy by a pure object-oriented language are: Encapsulation Polymorphism Inheritance All predefined types are objects Abstraction All operations executed on objects must be only through processes exposed to the objects. All user-defined types are objects

16. Why Java is not considered a pure object-oriented programming language?

Java is not considered a pure object-oriented programming language because pre-defined data types in Java are not managed as objects. Therefore, it is not an object-oriented language.

17. Explain class and object?

Class: It is a user-defined data type that works as a blueprint or template of an object. In a class, we describe variables, member functions, constants, and other functions. It does not use memory at run time. Classes cannot be considered as a data structure. It is an analytical entity for example data binding. Object: An object is a real-world entity that has attributes, properties, and behavior. It is guided as an instance of the class. It includes member functions, variables that we have described in the class. It consumes space in the memory. Different objects have various states or attributes, and behaviors.

18. Explain the concept of access specifiers?

In OOPS language, access specifiers work as a reserved keyword that sets the methods, accessibility, and other members of the class. It is also called access modifiers. It contains private, public, and protected specifiers. There is some additional access specifier that is based on language or language-specific. These access specifiers play a crucial role in acquiring one of the core functions of OOP that is encapsulation.

19. Explain encapsulation?

It binds the code and the data that work together in a single unit. For example, a class. Encapsulation also permits data-hiding as the data given in one class is hidden from another class.

20. Explain manipulators and their work in OOP?

Manipulators are supporting functions. It is used to influence or change the input or output stream. The change is achievable by using operators i.e. insertion («) and extraction (») operators. Note that the change of input or output stream doesn’t tell to modify the values of variables. Manipulators are of two types i.e. with arguments or without arguments. Examples of manipulators without arguments are endl, flush, ws, etc. Manipulators with arguments are setw(val), setiosflags(flag), setbase(val), setfill(c).

21. Tell the rules for forming a constructor?

It can’t be of the return type. It must contain the same name as the Class name. It can’t be static. It can’t be abstract. It can’t be overridden. It can’t be final.

22. Tell some characteristics of an abstract class?

Instantiation of an abstract class is not allowed. An abstract class must be inherited and Instantiation is not allowed. It can have both non-abstract and abstract methods. An abstract class must contain one abstract method and it should be declared. It is forever public. It is declared using the abstract

23. Can a class inherit the constructor of its base class?

No, a class can’t inherit the constructor of its base class.

24. Explain composition?

Composition is one of the essential concepts in OOP. It defines a class that positions one or more objects of another class in instance variables. It permits us to model a has-a connection between objects. We can find such a connection in the real world.

25. Explain the main benefits of composition?

Reutilizing existing code Design clean APIs Change the execution of a class used in a composition without adapting any exterior clients.

26. Differentiate Composition and Inheritance?

Inheritance represents an object having reusable properties of the base class. Compositions represent an object that holds other objects. Inheritance has only one object in memory (derived object) but, In Composition, the parent object contains references of all composed objects. Inheritance is “is a” connection among objects but Composition is “has a” connection among objects as per design perspective.

27. What is constructor chaining?

In OOPs, constructor chaining is a sequence of invoking constructors (of the same class) upon initializing an object. It is used when we want to invoke a number of constructors, one after another by using only an instance. In other words, if a class has more than one constructor (overloaded) and one of them tries to invoke another constructor, this process is known as constructor chaining. In C++, it is known as constructor delegation and it is present from C++ 11.

28. Explain Coupling in OOP?

In programming, a partition of concerns is called coupling. It simply means an object can’t instantly alter or change the state or behavior of other objects. It describes how strongly two objects are linked together. Coupling is of two types that is loose coupling, and tight coupling. Objects that are self-dependent and don’t instantly change the state of other objects are known as loosely coupled. Loose coupling creates the code more adaptable, changeable, and easier to work with. Objects that are dependent on other objects and can change the states of other objects are known as tightly coupled. It creates a position, where changing the code of one object also needs changing the code of other objects. The reuse of code is hard in tight coupling because we can’t split the code. So, using loose coupling is constantly a good habit.

29. Tell the names of operators that can’t be overloaded.

Ternary Operator (? :) Scope Resolution Operator (::) sizeof operator Pointer to Member Operator (.*) Member Access or Dot Operator (.)

30. Differentiate new and override modifiers?

The new modifier refers to the compiler to utilize the new implementation than the base class function. Whereas, Override modifier allows to override the base class function. virtual: It shows that a process may be overridden by an inheritor. override: Overrides the functionality of a virtual method in a base class, providing different functionality. new: Hides the actual method (which is not virtual), provides different functionality. This should be used only where it is completely necessary.

31. What do you understand by overloading and overriding, show with example?

Overloading: It is a concept in OOP when there are two or more methods is present in a class with a similar name but the method signature is changed. It is also called compile-time polymorphism. As shown in the code snippet, the method add() is an overloaded method. public class Sum
{
int a, b, c;
public int add();
{
c=a+b;
return c;
}
add(int a, int b);
{
//logic
}
add(int a, int b, int c);
{
//logic
}
add(double a, double b, double c);
{
//logic
}
//statements
}
Overriding: If a method with a similar method signature is available in both child and parent class is called method overriding. The methods should have a similar number of parameters and a similar type of parameter. It is also called runtime polymorphism and it overrides the value of the parent class method. As shown in the code snippet. class Dog
{
public void bark()
{
System.out.println(“woof “);
}
}
class Hound extends Dog
{
public void sniff()
{
System.out.println(“sniff “);
}
//overrides the method bark() of the Dog class
public void bark()
{
System.out.println(“bowl”);
}
}
public class OverridingExample
{
public static void main(String args[])
{
Dog dog = new Hound();
//invokes the bark() method of the Hound class
dog.bark();
}
}

32. What is Cohesion in OOP?

Cohesion is the degree to which the elements in a module belong together. It calculates the strength of the connection between the module and data. In short, cohesion describes the clarity of the responsibilities of a module. It is usually misunderstood with coupling. It concentrates on how one module or class is planned. The cohesiveness of the module or class is high the better is the object-oriented design.

33. Explain types of Cohesion in OOP:

Cohesion is two types that are High and Low. High cohesion is related to several qualities of software that consist of robustness, understandability, and reliability. Low cohesion is related to undesirable qualities like hard to maintain, reuse, test, or even understand. High cohesion is often related to loose coupling and vice versa.

34. Differentiate a base class and a superclass?

The base class is called the root class which is the most generalized class. Whereas, the superclass is the instantaneous parent class from which another class inherits.

35. Explain data abstraction and how can we achieve it?

It is a significant feature of OOP. It authorizes us to display only vital data or information to the user and hides the performance details from the user. To achieve data abstraction there are two ways that is: Abstract class Abstract method

36. Explain the different levels of data abstraction?

Physical Level: It is the lowliest level of data abstraction. It displays how the data is reserved in memory. Logical Level: It contains the information that is reserved in the database in the arrangement of tables. It also holds the connection among the data entities is fairly simple structures. At this level, the information presented to the user at the view level is unknown. View Level: It is the most top-level of data abstraction. The real database is seeable to the user. It eases the presentation of the database by an individual user.

37. Explain the different types of variables in OOP?

Instance Variable: It is an object-level variable that must be declared inside a class but outside a method, constructor, and block. It is made when an object is formed by using the new keyword. It can be used instantly by calling the variable name inside the class. Static Variable: It is a class-level variable that is declared with keyword static inside a class but outside of the method, constructor, and blocks. It reserves in static memory. It is visibly similar to the instance variable. The defaulting value of a static variable is similar to the instance variable. It can be used by calling the class_name.variable_name. Local Variable: It is a method-level variable, it is declared in method, block, or constructor. You cannot use the access modifier with local variables. It is visual only to the method, constructor, and block in which it is declared. Internally, it is executed at the stack level. Reference Variable: It is a variable that indicates an object of the class. It tells the location of the object that is reserved in the memory.

38. Can we overload a constructor?

Yes, we can overload a constructor by modifying the number of arguments received by the constructor or by modifying the data type of the parameters. For example: public class Demo
{
Demo()
{
//logic
}
Demo(String str) //overloaded constructor
{
//logic
}
Demo(double d) //overloaded constructor
{
//logic
}
//statements
}

39. Is it possible to overload the main() method in Java?

Yes, it is possible to overload the main() method in Java. Any number of main() methods can be specified in the class, but the method signature should be different. For example: class OverloadMain
{
public static void main(int a) //overloaded main method
{
System.out.println(a);
}
public static void main(String args[])
{
System.out.println(“main method invoked”);
main(6);
}
}

40. Tell some real-world examples of polymorphism?

Polymorphism means one that has various forms. A person who plays different roles at various palaces or situations is a good real-world example of polymorphism. At home, a person can be a father, husband, or son. At the office, the same person becomes a boss or employee. During transportation, he becomes a passenger. At a shop, he becomes a customer. Hence, the same person has different behavior in different circumstances. It is called polymorphism.

41. Is it possible to create an instance of an abstract class?

No, it is not possible to create an instance of an abstract class because it don’t possess a complete implementation. Yet, instances of subclass inheriting the abstract class can be made.

42. Explain an interface?

It is a concept of OOPs that permits you to declare methods without describing them. Unlike classes, interfaces are not blueprints as they do not have clear instructions or actions to be done. Any class that executes an interface describes the methods of the interface.

43. Explain virtual functions?

Virtual functions are those functions that are available in the parent class and overridden by the subclass. These functions are is useful in achieving runtime polymorphism.

44. Explain pure virtual functions?

Abstract functions or Pure virtual functions are those functions that are only declared in the base class. This simply means that they don’t have any definition in the base class and ought to be redefined in the subclass.

45. Explain constructor?

A constructor is a unique type of method that consists of a similar name as the class and is mainly used to initialize objects of that class.

46. Explain destructor?

A destructor is a way that itself invoke when an object is destructed. The destructor also retrieves the heap space that was assigned to the destructed object, shuts the files and database links of the object, etc.

47. Name different types of constructors in OOPS

Default constructor Copy constructor Parameterized constructor Private constructor Static constructor

48. Explain a copy constructor?

A copy constructor makes objects by duplicating variables from another object of a similar class. The primary aim of a copy constructor is to make a new object from a current one.

49. Tell the use of ‘finalize’?

Finalize is an object method that is used to release up unlooked resources and cleanup before Garbage Collection (GC). It conducts memory management tasks.

50. Explain Garbage Collection (GC)?

Garbage Collection (GC) is an execution of automated memory management. The Garbage collector releases up space consumed by objects that are no longer in use.

Want to prepare for these languages:

Recent Articles