OOPS Interview questions and Answers , Basics of OOPS, Oject, Class, Abstraction, Encapsulation, Encapsulation
Interview questions and answers for OOPS, oops interview questions and answers for
experienced in java and .NET. Object Oriented Programming system Interview questions and Answers, Basics of
OOPS, Oject, Class, Abstraction, Encapsulation, Encapsulation, Inheritance, constructor,
constructor. Interview Qusetion and Answers for exception handling.
1. What is OOPS?
OOPS is abbreviated as Object Oriented Programming system in which programs are
considered as a collection of objects. Object-oriented programming is a programming
paradigm based on the concept of "objects", which may contain data, in the form
of fields, often known as attributes; and code, in the form of procedures, often
known as methods.
2. 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.
3. What is an object?
Object is termed as an instance of a class, and it has its own state, behavior and
identity.
4. 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.
5. What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined
in another class. If inheritance applied on one class is called Single Inheritance,
and if it depends on multiple classes, then it is called multiple Inheritance.
6. Waht is constructor?
A constructor is a method used to initialize the state of an object, and it gets
invoked at the time of object creation.
7. What is Destructor?
A destructor is a method which is automatically called when the object is made of
scope or destroyed.
8. 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.
9. What is Polymorphism?
Polymorphism is nothing but assigning behavior or value in a subclass to something
that was already declared in the main class.
10. What is function overloading?
Function overloading an as a normal 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.
11. 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
12. 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 Abstract method. Java allows only abstract method in abstract class
while for other languages allow non-abstract method as well.
13. 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. This will overrides the implementation
in the superclass by providing the same method name, same parameter and same return
type.
14. What is an interface?
An interface is a collection of an abstract method. If the class implements an inheritance,
and then thereby inherits all the abstract methods of an interface.
15. 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 data and it doesn’t require strict validation
, but classes are used to encapsulates and inherit data which requires strict validation.
16. 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.
17. 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 associated with the class and its child class.
18. 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 required details for an object, not
the inner constructors, 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.
19. 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.
20. What are 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.
21. 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.
22. 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.
23. 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.
24. What is the default access modifier in a class?
The default access modifier of a class is Private by default.
25. 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.
26. What are all the operators that cannot be overloaded?
ollowing are the operators that cannot be overloaded -.
- Scope Resolution (:: )
- Member Selection (.)
- Member selection through a pointer to function (.*)
27. What is a base class, sub class, and super class?
The base class is the most generalized class, and it is said to be a root class.
A Sub class is a class that inherits from one or more base classes. The superclass
is the parent class from which another class inherits.
28. How many instances can be created for an abstract class?
Zero instances will be created for an abstract class.