TOP OOPs Interview Questions and Answers
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.
What is the default access modifier in a class?
The default access modifier of a class is Private by default.
What is pure virtual function?
A pure virtual function is a function which can be overridden in the derived classbut cannot be defined. A virtual function can be declared as Pure by using the operator =0.
Virtual void function1() // Virtual, Not pure
Virtual void function2() = 0 //Pure virtual
What are all the operators that cannot be overloaded?
Following are the operators that cannot be overloaded -.
- Scope Resolution (:: )
- Member Selection (.)
- Member selection through a pointer to function (.*)
What is dynamic or run time polymorphism?
Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name,same signature but with different implementation.
Do we require parameter for constructors?
No, we do not require parameter for constructors.
What is a copy constructor?
This is a special constructor for creating a new object as a copy of an existing object. There will be always only on copy constructor that can be either defined by the user or the system.
What does the keyword virtual represented in the method definition?
It means, we can override the method.
Whether static method can use non static members?
What arebase class, sub class and super class?
Base class is the most generalized class , and it is said to be a root class.
Sub class is a class that inherits from one or more base classes.
Super class is the parent class from which another class inherits.
What is static and dynamic binding?
Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time , and it is also called as early Binding.
Dynamic binding is a binding in which name can be associated with the class during execution time , and it is also called as Late Binding.
How many instances can be created for an abstract class?
Zero instances will be created for an abstract class.
Which keyword can be used for overloading?
Operator keyword is used for overloading.
What is the default access specifier in a class definition?
Private access specifier is used in a class definition.
Which OOPS concept is used as reuse mechanism?
Inheritance is the OOPS concept that can be used as reuse mechanism.
Which OOPS concept exposes only necessary information to the calling functions?
Data Hiding / Abstraction