0% found this document useful (0 votes)
37 views8 pages

Oops Interview Questions and Answers

Uploaded by

fanep97171
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views8 pages

Oops Interview Questions and Answers

Uploaded by

fanep97171
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

OOPS INTERVIEW QUESTIONS AND ANSWERS

1. what is programming paradigm?


A programming paradigm is a fundamental style or approach to
writing computer programs. such as functional, structural, object-
oriented, functional, etc., each with its own principles and practices.

2. What is the type of programming paradigm?

 Imperative Programming is a programming paradigm that focuses


on describing a sequence of statements that change a program's
state. In imperative programming, you specify how the program
should achieve a particular goal step by step.

 Procedural programming is a programming paradigm that focuses


on using procedures or functions to structure code. In procedural
programming, a program is divided into smaller, reusable
procedures or functions, each responsible for performing a specific
task.

 Declarative programming is a programming paradigm that


emphasizes describing what should be achieved, rather than how to
achieve it. Example: SQL (Structured Query Language)

 Event-driven programming is a programming paradigm where the


flow of a program's execution is determined by events, such as user
actions. Example. DOM

3. Why we go for oops?


To improve code readability and reusability. Using functionalities
like data abstraction and hiding, OOPs ensure the security of the cod.

4. What is oops?
Object-Oriented Programming (OOP) is a programming paradigm
the organize a code using classes and objects. It works on the principles
of abstraction, encapsulation, inheritance, and polymorphism.
5. What is class & objects?
A class is simply a representation of a type of object. It is the
blueprint/plan/template that describes the details of an object.
An object is an instance of a class. It contains both data (attributes) and
behaviours (methods) associated with that entity.

6. What is Encapsulation?
Encapsulation is a way to restrict the direct access to some
components of an object. Encapsulation can be used to hide both data
members and data functions or methods associated with an instantiated
class or object.
There are three levels of encapsulation.
 Public: Accessible from anywhere.
 Protected: Accessible within the class and its children.
 Private: Accessible only within the class itself.

7. What is Polymorphism?
The behaviour of the same object or function is different in
different contexts.

8. What is compile time polymorphism?


Compile-time polymorphism is done by overloading an operator or
function. Overloaded functions are called by comparing the data types
and number of parameters.

9. What is runtime polymorphism?


Run-time polymorphism, or dynamic polymorphism, means that
the behaviour of a method is determined by the actual type of the object
at runtime.

10. What is Overloading and overriding?


 Method Overloading: Method overloading occurs when multiple
methods in the same class or subclass have the same name but
different parameters (number or type of parameters).
 Method overriding (dynamic binding): Method overriding occurs
when a subclass provides a specific implementation for a method
that is already defined in its superclass. The overriding method has
the same name, return type, and parameters as the method in the
superclass.
11. What is type of binding?
 Static Binding (Early Binding): The method to call is decided by
the compiler at compile-time based on the number of variable’s
and declared type.
 Dynamic Binding (Late Binding): The method to call is determined
at runtime based on the actual object's type.

12. What is Operator Overloading?


When an operator is updated to be used for user-defined data types
(objects etc.), this is known as operator overloading.

13. What is Inheritance?


 Inheritance is a mechanism in which one class acquires the
property of another class.
 Inheritance is defined as a mechanism where the sub or child class
inherits the properties and characteristics of the super class.

14. What are the types of inheritance?


 Single Inheritance: A class inherits from only one parent class.
 Multiple Inheritance: A class inherits from more than one parent
class.
 Multilevel Inheritance: A chain of inheritance in which a subclass
becomes the superclass for another subclass.
 Hierarchical Inheritance: Multiple subclasses inherit from a single
superclass.
 Hybrid Inheritance: A combination of two or more types of
inheritance.
15. What is constructor?
A constructor is a method used to initialize the object's attributes, and it
gets invoked at the time
of object creation.
 Constructor Name should be the same as a class name.
 A constructor must have no return type.

16. What is destructor?


 A destructor is a method that gets called automatically when an
object is destroyed or goes out of scope.
 The primary purpose of a destructor is to release any resources or
perform clean-up operations associated with the object, such as
closing files, releasing memory, or terminating connections.
17. What is manipulators?
Manipulators are special functions or objects used to formatting of
input and output operations, allowing you to modify how data is
displayed or read in a program.

18. 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. It is used for small and simple functions
like getter and setter.

19. What is Virtual function?


A virtual function is a function that is declared in a base class, can
be override in derived classes to provide specialized implementations.

20. What is friend function?


It's a function that can access and modify the private and protected
properties and methods of the class, even though it's not a member of the
class itself.

21. What is abstraction?


Abstraction is a process of hiding the implementation details and
showing only functionality to the user.

22. What is abstract class?


An abstract class is like a blueprint for other classes. It's a class that
defines a set of rules or requirements for other classes to follow. It can
have abstract and non-abstract methods (0 -100%). Creation of an object
is not possible with an abstract class.

23. What is finalize method?


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

24. What is super class?


It is used to access fields and methods of the superclass from
within a subclass. super can also be used to call constructors of the
superclass.
25. What is abstract method?
It's a method declared in a class but without any implementation
details. Instead, subclasses of that class to provide the specific code for
that method.

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

27. 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, File I/O
exceptions. Those exceptions are handled through exception handling
mechanism like try, catch, and throw keywords

28. What is token?


Token: A token is a group of characters having collective meaning.
Keywords, identifiers, constants, string literals, comma, punctuation and
operators are examples of tokens.

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

30. What are sealed modifiers?


When you declare a method as sealed within a class, it means that
no subclass can override that method. The method's implementation in
the base class becomes final and cannot be changed in derived classes.
This modifier cannot be used to static members.

31. 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 super Keyword from a derived class.
32. 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.

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

34. What is 'this' pointer? & What is the default access modifier in a class?
this pointer refers to the current object of a class. The default
access modifier of a class is Private by default.

35. Whether static method can use non static members?


False.

36. What is 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

37. Difference between error and exception?


 Errors: Errors are the issues that usually came from external
factors, like hardware or system failures. They are non-recoverable
and lead to the termination of the program.
 Exception: An exception is an event that occurs during the
execution of a program.

38. Difference between structure and class?


Class: Members of a class are private by default.
Structure: Members of a structure are public by default.
Class: Supports inheritance, allowing you to create subclasses with shared
behaviour.
Structure: Does not support inheritance; it's used for simple data storage.
Class: Uses more memory because it's a reference type.
Structure: Uses less memory because it's a value type.

You might also like