Professional Documents
Culture Documents
OOP Interview Question
OOP Interview Question
Relations in OOP
Inheritance “Is- a” relationship, Parent child
relationship.
Association “Using” relationship, exe. A person eat
bread. One object uses other object.
Composition “has a” relationship. A child object cannot
exist without parent object. Strong
Relationship
Aggregation “Part of or a whole”. A part of object can
exist outside the whole is aggregation. For
example Chair and Room. Weak
Relationship.
Other Concepts
Class Class is a blueprint which is used to create
objects.
Object Instance of a class is object.
OOP OOP is a programming paradigm that
relies on classes and objects.
Interface Interface are methods to interact outside
world.
Overriding If derived class defines a method which is
already defined in its base class but
changes implementation.
Overloading More than one function with same name
but with different parameters or return
type. Based on parameters we pass during
function call compiler will decide which
function is called.
Abstract Class Abstract class is the super class or base
class from which we instantiate other
derived or child classes.
Concrete Class The entities we see in real world are
concrete objects and classes made against
these objects are called concrete classes.
Example: vehicle is a base class, and car,
truck and bus are the concrete classes of
vehicle class.
Inline Function Inline function runs faster than normal
function. Because compiler replaces
function call with function code itself and
then compiles the entire code. In other
words, if a function is inline then compiler
places copy of the code of that function at
each point where the function is called at
compile time.
We will make a function inline when it is
too small and often called.
Constructor Main purpose of constructor is to construct
Default Constructor an object of a class or it is used to initialize
Copy constructor all the data members of a class.
Shallow copy Constructor can be called implicitly and
Deep copy explicitly.
Default constructor is a constructor which
have no parameters or if it has parameters
then it has default values in it.
A copy constructor copies the data of one
object into another object. Purpose of copy
constructor is to initialize a new instance
from the values of an existing instance.
Shallow copy copies the references
(pointers etc.) of an object. It is a bit-wise
copy. Bit-wise means you copy the bits of
the source class to the target class using
memcpy() or something similar. A new
object is created that has an exact copy of
values in the original object. If any of the
fields are references to other objects, only
the reference addresses are copied, i.e. only
the memory address is copied.
Deep copy copies the entire object (struc).
Destructor It is a member function that is invoked
automatically when the object goes out of
scope or is explicitly destroyed by a call to
delete. Example destructor for a class
String is ~String().
Accessor Functions To access private data member, accessor
Mutator Functions function is used. These are like get and set
functions in c#.
Accessors are member functions that allow
access to data members.
Member functions that allow for
modification of the data members are
called mutators.
This pointer It is a pointer which is accessible only
within non-static member function of a
class. It points to the object for which the
member function is called.
Constant member function The object called by these functions cannot
be modified. “const” keyword is used
before function name.
Local, Global and Static Variables Local variable is declared, initialized and
used inside of a function. Is is similar to
normal variable. Its lifetime begins when
function is called and ends when function is
completed. We can have local variables of
same name in different functions, because
local variables are only recognized by the
function in which they are declared.