Interview questions for Object-Oriented Programming

Object-Oriented Programming has become an essential part of software development. Most of today’s top programming languages are OOPs compatible. Professionals aiming for a lucrative career in the IT world should possess a strong understanding of OOPs concepts.

1. What is OOPs?

OOPs(Object Oriented Programming) is a programming concept that creates objects for data and methods. It works on the principles of encapsulation, classes, abstraction, aggregation, polymorphism, and inheritance. OOPs aims to create, re-use, and manipulate objects throughout the program to get results.
OOPs is popularly used in modern programming languages like Java.
n simple language, a class can be considered as the blueprint or template, based on which objects can be created. So the Objects are considered the instance of a class, and are therefore sometimes called “instances”. The term “characteristics” refers to the “what” about the Object, and the term “behavior” refers to the “how” about the Object.
For example, if we consider a car, then based on the OOPs model:
• Class = A specific car model, such as Audi A4, BMW I8, Maruti Suzuki Vitara Brezza, etc.
• Object = A specific car of any model, like the car you own
• Characteristics = What is the color of your car? What is the Chassis number of your car? etc
• Behavior = How to start the car? How to change the gear of the car? etc.
Characteristics are also known as data, attributes, or properties, and Behaviours are also known as the functions, procedures or methods, in the programming language.

2.  What are the four basics of OOPs?

The four main basics of OOPs in Java are:
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Abstraction – It means using simple things to represent complexity.
Encapsulation – It’s a practice of keeping fields in a private class, then accessing through public methods.
Inheritance – It’s a unique feature of OOPs that lets users create new classes sharing some of the existing classes’ attributes.
Polymorphism – It lets you use the same word to mean different things in different contexts. Method overriding and Method overloading are the two forms of Polymorphism. Method overloading occurs when the code itself implies different meanings. Method Overriding occurs when the values of the supplied variables indicate different meanings.

3) What are the benefits of OOPs?

OOPs is a core development approach used in modern programming languages. Let’s see the advantages of OOPs that it offers:
• Code reusability through inheritance
• Data redundancy
• Security
• Code maintenance
• Easy troubleshooting
• Better productivity
• Polymorphism flexibility
• Effective problem solving

4) What are the principles of OOPs?

The five concepts that make up solid principles of OOPs:
• Single Responsibility Principle.
• Liskov Substitution principle.
• Open/Closed principle.
• Dependency Inversion principle.
• Interface Segregation Principle.

5) Who invented OOPs?

Alan Kay put the idea of object orientation in the early 1970s. The concept includes classes, multiple instances of classes, and the message passing between the objects of one class and another.

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.

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

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

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

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

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

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

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

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

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

16. 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 asclass name.
•Constructor must have no return type.

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

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

leave your comment


Your email address will not be published. Required fields are marked *