Some OOPs Interview Questions

Kesavi Kanesalingam
3 min readApr 3, 2020

1.What is OOP?
Object Oriented Programming (OOP) is a programming paradigm where the complete software operates as a bunch of objects talking to each other. An object is a collection of data and methods that operate on its data.

2. What are main features of OOP?
Encapsulation
Polymorphism
Inheritance

3. What is a class?
A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects of a certain kind. A class is a prototype that consists of objects in different states and with different behaviors. It has a number of methods that are common the objects present within that class.

4. What is an object?
An object is a specimen of a class. Software objects are often used to model real-world objects you find in everyday life. An object is a real-world entity which is the basic unit of OOPs for example chair, cat, dog, etc. Different objects have different states or attributes, and behaviors.

5. What is Encapsulation?
Encapsulation is one of the fundamentals of OOP (object-oriented programming). It refers to the bundling of data with the methods that operate on that data. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties’ direct access to them.

6. What is Polymorphism?
Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms. A language that features polymorphism allows developers to program in the general rather than program in the specific.

7. What do you mean by inheritance?
Inheritance is a mechanism wherein a new class is derived from an existing class. In Java, classes may inherit or acquire the properties and methods of other classes. A class derived from another class is called a subclass, whereas the class from which a subclass is derived is called a superclass.

8. What is the difference between a class and a structure?
Class:
A class is a reference type.
While instantiating a class, CLR allocates memory for its instance in heap.
Classes support inheritance.
Variables of a class can be assigned as null.
Class can contain constructor/destructor.

Structure:
A structure is a value type.
In structure, memory is allocated on stack.
Structures do not support inheritance.
Structure members cannot have null values.
Structure does not require constructor/destructor and members can be initialiazed automatically.

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

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

11. What is the function overloading?
Overloading occurs when two or more methods in one class have the same method name but different parameters.

12. What is the function overriding?
Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class. Overriding allows a child class to provide a specific implementation of a method that is already provided its parent class.

13. What is early and late Binding?
Early Binding: The binding which can be resolved at compile time by the compiler is known as static or early binding. Binding of all the static, private and final methods is done at compile-time.
Late binding: In the late binding or dynamic binding, the compiler doesn’t decide the method to be called. Overriding is a perfect example of dynamic binding. In overriding both parent and child classes have the same method.

14. What are a base class, subclass, and superclass?
Base class(root) -the most generalized class
Subclass (child) -the class that inherits from another class
Superclass (parent) -the class being inherited from

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

--

--