Вы находитесь на странице: 1из 9

OOPS

1. What is Object Oriented Programming?


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. Why OOP?
The main advantage of OOP is better manageable code that covers following.
The overall understanding of the software is increased as the distance between the language
spoken by developers and that spoken by users.
Object orientation eases maintenance by the use of encapsulation. One can easily change
the underlying representation by keeping the methods same.
OOP paradigm is mainly useful for relatively big software.
3. What are main features of OOP?
Encapsulation
Polymorphism
Inheritance
4. What is encapsulation?
Encapsulation is referred to one of the following two notions.
1) Data hiding: A language feature to restrict access to members of an object. For example,
private and protected members in C++.
2) Bundling of data and methods together: Data and methods that operate on that data are
bundled together.
5. What is Polymorphism? How is it supported by C++?
Polymorphism means that some code or operations or objects behave differently in different
contexts. In C++, following features support polymorphism.
Compile Time Polymorphism: Compile time polymorphism means compiler knows which
function should be called when a polymorphic call is made. C++ supports compiler time
polymorphism by supporting features like templates, function overloading and default
arguments.
Run Time Polymorphism: Run time polymorphism is supported by virtual functions. The idea
is, virtual functions are called according to the type of object pointed or referred, not
according to the type of pointer or reference. In other words, virtual functions are resolved
late, at runtime.
6. What is Inheritance? What is the purpose?
The idea of inheritance is simple, a class is based on another class and uses data and
implementation of the other class.
The purpose of inheritance is Code Reuse.
7. What is Abstraction?
The first thing with which one is confronted when writing programs is the problem. Typically
we are confronted with “real-life” problems and we want to make life easier by providing a
program for the problem. However, real-life problems are nebulous and the first thing we
have to do is to try to understand the problem to separate necessary from unnecessary
details: We try to obtain our own abstract view, or model, of the problem. This process of
modeling is called abstraction.
1. What is Object Oriented Programming?
Object-Oriented Programming (OOP) is a
software programming technique where the
focus is on objects rather than procedures. In
OOP, an instance of a class is termed as
Object.
2. What are the basic concepts of OOPS?
The basic concepts of OOP are Abstraction,
Encapsulation, Inheritance, and Polymorphism.
3. What are Manipulators?
These are the functions that be used on an
object in conjunction with the operators’ insertion (<<) and extraction (>>) . For eg.
endl and setw.
4. What is a class?
A class is the basic representation of an object. It contains the details of an object.
Check Course Details of Our C++ Deep Dive Training Here
5. What is an object?
An object refers to the specific instance of a class where the object can be a mixture
of data structures, functions and variables.
6. Difference between class and an object?
An Object can contain information while a class cannot hold any information.
It is possible for a class to have subclasses whereas an Object cannot have sub-
objects.
7. What is the difference between structure and a class?
A class groups data and methods while a structure groups only data
a. By default, the structure access type is public while that of a class is private
b. Structures do not require strict validation while class requires strict validation as it
encapsulates and inherits data.
8. What is encapsulation?
a. Encapsulation can refer to either Data hiding or Bundling of data & methods
together.
b. Data hiding: This is a language feature to confine access only to the object members.
Eg. private & protected members in C++.
c. Bundling of data and methods together: This refers to how methods and data that
function on that particular data are bundled together.
9. What is Polymorphism? How is it supported by C++?
According to Polymorphism, in different contexts, some objects/ code/operations
behave differently.
These features support polymorphism in C++
Compile Time Polymorphism: According to Compile time polymorphism, when a
polymorphic call is made the compiler should know which operation is to be
executed. Supporting attributes in C++ like templates, function overloading and
default arguments enables it to supports compile time polymorphism
Run Time Polymorphism: Virtual functions support this polymorphism. They are
called according to the kind of object referred or pointed, not by kind of type of
pointer or reference. In short, virtual functions are determined late, at runtime.
10. What is Inheritance? What is the purpose?
a. The basic purpose of Inheritance is Code Reuse. According to this principle, a class is
constructed on another class and the utilizes the data and implementation of the
latter.
11. What is early and late binding?
a. The compiler performs a process where it matches the function call with the
function definition. This is termed as Binding. It can take place during compile time
or at runtime. Early binding is also called as Static binding. It means assigning
the value to a variable during compile time. Late binding is also called as Dynamic
binding; the values to the variables are assigned during runtime.
12. What is Abstraction?
a. The first step in writing a program is to define a problem. These problems are
derived from real-world issues that the programmer wants to find a solution to. It is
necessary to sift relevant details from irrelevant ones when it comes to real-world
issues. In this process, the programmer comes up with his own abstract model of the
problem. This process is termed as Abstraction.
13. Define a constructor?
a. The constructor is a technique used to initialize the state of an object which gets
invoked during object creation.
14. What are the rules for a Constructor?
a. The name of the constructor should be the same as that of the class
b. It should not have a return type
15. Define Destructor?
a. A Destructor is a function that is called automatically when the object is destroyed or
when its scope ends.
16. What is an Inline function?
a. An inline function is an enhancement feature in C++ that is used to increase the
derivprogram’s execution time.
What is a virtual function?
b. A virtual function is a member function declared within a base class which can be
overridden by the derived class. You can call a virtual function for a derived class
object when you refer to it using a pointer or a reference to the base class and then
execute the function version of the derived class.
c. The virtual function makes certain the correct function is called for an object
irrespective of the kind of pointer/reference used for the function call. The keyword
virtual can be used to implement this function.
17. What is a friend function?
a. A friend function is a friend of a class that is given access to that class’s public,
private and protected data. It cannot access the data if it is defined outside that
class. It can be defined anywhere in the class declaration and access control
keywords like public, private or protected cannot affect it.
18. What is function overloading?
a. Function overloading is a function that enables the programmers to create multiple
functions with the same name but different implementation. In other words, these
methods with the same name differ from each other by the kind of input and output
of the function.
b. For eg.
c. void add(int& a, int& b);
d. void add(double& a, double& b);
e. void add(struct bob& a, struct bob& b);
19. What is operator overloading?
a. Operator overloading is also called as ad-hoc polymorphism. It is a function where all
the operators have different implementation depending on its argument type.
b. Operator overloading is usually defined by the programming language, programmer
or both.
20. What is an abstract class?
a. An abstract class is a class which can contain only abstract methods. This class also
cannot be instantiated and requires subclasses to give implementation to the
abstract methods.
21. What is a ternary operator?
a. In several programming languages, the ternary operator is also called a conditional
operator. It is an operator which takes three arguments: the first argument is a
comparison argument, the second argument is the result of a true comparison and
the last argument is the result of a false comparison. It is like a short way of writing
an if-else statement.
22. What is the use of finalize method?
a. Finalize method is a technique that enables the programmer to clean up the
resources which are not being used currently. This method is protected and hence
accessible only to that particular class or by a derived class.
23. What is a token?
a. Token, in programming, is a basic component of a code that is recognized by the
compiler. Eg. Identifiers, String Literals, Constants & Operators.
24. What are access modifiers?
a. Access modifiers are keywords that determine the accessibility of the methods,
classes and other members.
25. List out the five access modifiers
a. The 5 types of access modifiers are Private, Protected, Public, Friend & Protected
friend.
26. What are sealed modifiers?
27. Sealed modifiers are the access modifiers that cannot be inherited and are concrete. They
cannot be applied to static members and can be applied to instance methods, events,
indexes, and properties.

28. How can we call the base method without creating an instance?

1. It is possible
ii. if it is a static method
iii. By inheriting from that particular class
iv. Using basic keyword from a derived class

29. What is the difference between new and override?

i. While the new modifier tells the compiler to use the new implementation
rather than the base class function, Override modifier helps to override base
class function.

30. What are the various types of constructors?


i. There are three types of constructors. They are:
ii. Default Constructor
iii. Parametric Constructor
iv. Copy Constructor

1.Can you explain the different types of Inheritance?

There are four main types of Inheritance in OOPS as listed below:

• Single Inheritance: This includes one base class along with one derived class.
• Hierarchical Inheritance: This inheritance class includes one base class as well
as multiple derived classes of the same base class.
• Multilevel Inheritance: This includes a class derived from a derived class.
• Multiple Inheritance: This class includes several base classes as well as a
derived class.

2. Explain the concept of a hashtable.

Hashtable is used to store multiple items. Each of these items is linked with their
own unique string key and can be accessed using the key associated with it.

3. What is Association?

Association can be described as a relationship that exists between two objects


with multiplicity.

4. Can you touch upon the core concepts of OOPS?

The core concepts of OOPS are as below:


• Encapsulation
• Polymorphism
• Inheritance
• Abstraction
• Composition
• Association
• Aggregation

5. Can you list out some examples of tokens?

Here are some common examples of tokens:


• Keywords
• Commas
• Constants
• Identifiers
• Brackets
• Operators

6. Can you describe Polymorphism and list out the different types of
Polymorphism?

Polymorphism can be termed as the ability to take on more than one form. In
OOPS, Polymorphism means a single interface with multiple implementations for
a certain class of action.

Polymorphism can further be classified into two distinct types:


• Static
• Dynamic
You may also like: 6 Questions to ask at the end of your Job Interview
 10 Tips to stay focused in an Interview

7. Can you explain what Access Modifiers are?

Access modifiers are used to figure out the scope of the method or variables
accessible from other various objects or classes.

Access modifiers can be of five types:


• Private
• Public
• Protected
• Friend
• Protected Friend

8. Can you list out the different types of constructors?

Constructors are of three types as listed below:


• Default Constructor: Contains no parameters.
• Parametric Constructor: Contains parameters. This parameter is used to create
a new class instance and for simultaneously passing arguments.
• Copy Constructor: This is used to create a new object as a copy of an existing
object.

In addition to the above-mentioned questions, here’s an additional list of 8


frequently asked OOPS Interview questions that will surely assist you in your bid
to crack your all-important OOPS interview.

a. Can you explain what a multicast Delegate is?


b. Please describe the friend function.
c. Explain the what Information Hiding is in OOPS.
d. Explain the concepts of Overloading and Overriding Polymorphism.
e. Describe the concept of Enum?
f. Explain multiple inheritance.
g. Can you point out the differences between Shadowing and Overriding?
h. Touch upon the differences between Static and Dynamic polymorphism.

1.What is OOPS?

OOPS is abbreviated as Object Oriented Programming system in which programs are


considered as a collection of objects. Each object is nothing but an instance of a class.

2 . Write basic concepts of OOPS?

Following are the concepts of OOPS and are as follows:.

Abstraction.

Encapsulation.
Inheritance.

Polymorphism.

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

4. What is an object?

Object is termed as an instance of a class, and it has its own state, behavior and identity.

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

Levels are Public,Protected, Private, Internal and Protected Internal.

6 . What is Polymorphism?

Polymorphism is nothing butassigning behavior or value in a subclass to something that


was already declared in the main class. Simply, polymorphism takes more than one form.

7 . What is Inheritance?

Inheritance is a concept where one class shares the structure and behavior defined in
another class. Ifinheritance applied on one class is called Single Inheritance, and if it
depends on multiple classes, then it is called multiple Inheritance.

8. What are manipulators?

Manipulators are the functions which can be used in conjunction with the insertion (<<)
and extraction (>>) operators on an object. Examples are endl and setw.

9. Define a constructor?

Constructor is a method used to initialize the state of an object, and it gets invoked at the
time of object creation. Rules forconstructor are:
Constructor Name should be same asclass name.

Constructor must have no return type.

10. Define Destructor?

Destructor is a method which is automatically called when the object ismade ofscope or
destroyed. Destructor name is also same asclass name but with the tilde symbol before the
name.

11. What is Inline function?

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.

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

13. What is an abstract class?

An abstract class is a class which cannot be instantiated. Creation of an object is not


possible with 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
language it allows non-abstract method as well.

14. What is an interface?

An interface is a collection of abstract method. If the class implements an inheritance, and


then thereby inherits all the abstract methods of an interface.

15. What is exception handling?

Exception is an event that occurs during the execution of a program. Exceptions can be of
any type — Run time exception, Error exceptions. Those exceptions are handled properly
through exception handling mechanism like try, catch and throw keywords.

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

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

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

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

Class can have sub-classes, and an object doesn’t have sub-objects.

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

Вам также может понравиться