Professional Documents
Culture Documents
1) What is OOPS?
There are various OOP languages but the most widely used are:
o Python
o Java
o Go
o Dart
o C++
o C#
o Ruby
The aim of OOP is to implement real-world entities like inheritance, hiding, polymorphism in
programming. The main purpose of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except that function.
o Inheritance
o Encapsulation
o Polymorphism
o Data Abstraction
Advantages of OOP
Disadvantages of OOP
9) What do you understand by pure object-oriented language? Why Java is not a pure
object-oriented programming language?
The programming language is called pure object-oriented language that treats everything
inside the program as an object. The primitive types are not supported by the pure OOPs
language. There are some other features that must satisfy by a pure object-oriented language:
o Encapsulation
o Inheritance
o Polymorphism
o Abstraction
o All predefined types are objects
o All user-defined types are objects
o All operations performed on objects must be only through methods exposed to the
objects.
Java is not a pure object-oriented programming language because pre-defined data types
in Java are not treated as objects. Hence, it is not an object-oriented language.
10) What do you understand by class and object? Also, give example.
Object: An object is a real-world entity that has attributes, behavior, and properties. It is
referred to as an instance of the class. It contains member functions, variables that we have
defined in the class. It occupies space in the memory. Different objects have different states
or attributes, and behaviors.
Class Object
It is conceptual. It is real.
It binds data and methods together into a single It is just like a variable of a class.
unit.
It does not occupy space in the memory. It occupies space in the memory.
It uses the keyword class when declared. It uses the new keyword to create an object.
A class can exist without any object. Objects cannot exist without a class
12) What are the key differences between class and structure?
Class Structure
Class is a group of common objects that shares The structure is a collection of different
common properties. data types.
It deals with data members and member functions. It deals with data members only.
It's members are private by default. It's members are public by default.
The keyword class defines a class. The keyword struct defines a structure.
8. Can you call the base class method without creating an instance?
Yes, you can call the base class without instantiating it if:
It is a static method
The base class is inherited by some other subclass
Access modifiers determine the scope of the method or variables that can be accessed from
other various objects or classes. There are five types of access modifiers, and they are as
follows:
Private
Protected
Public
Friend
Protected Friend
Manipulators are helping functions. It is used to manipulate or modify the input or output
stream. The modification is possible by using the insertion (<<) and extraction (>>)
operators
The example of manipulators that do not have arguments is endl, ws, flush, etc. Manipulators
with arguments are setw(val), setfill(c), setbase(val), setiosflags(flag).
A constructor is a special type of method that has the same name as the class and is used to
initialize objects of that class.
Rules for constructor are:
Default constructor
Parameterized constructor
Copy constructor
Static constructor
Private constructor
Copy Constructor- The copy constructor in C++ is used to copy data of one object to
another.
40. What is the use of ‘finalize’?
Finalize as an object method used to free up unmanaged resources and cleanup before
Garbage Collection(GC). It performs memory management tasks.
Inheritance is a feature of OOPs which allows classes inherit common properties from other
classes. This property helps you get rid of redundant code thereby reducing the overall size of
the code.
Single inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance
Hybrid inheritance
12. What is the difference between multiple and multilevel inheritance?
Hierarchical inheritance refers to inheritance where one base class has more than one
subclasses. For example, the vehicle class can have ‘car’, ‘bike’, etc as its subclasses.
Increases the time and effort required to execute a program as it requires jumping
back and forth between different classes
The parent class and the child class get tightly coupled
Any modifications to the program would require changes both in the parent as well as
the child class
Needs careful implementation else would lead to incorrect results
What is Polymorphism?
Polymorphism is nothing but assigning behavior or value in a subclass to something
that was already declared in the main class. Simply, polymorphism takes more than
one form.
Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time.
An example of compile-time polymorphism is method overloading.
If a class has multiple methods having same name but different in parameters, it is
known as Method Overloading.
If subclass (child class) has the same method as declared in the parent class, it is known
as method overriding
Operator overloading refers to implementing operators using user-defined types based on the
arguments passed along with it.
Overloading Overriding
Child class redefining methods present in the
Two or more methods having the same name
base class with the same parameters/
but different parameters or signature
signature
Resolved during compile-time Resolved during runtime
25. What is encapsulation?
Encapsulation refers to binding the data and the code that works on that together in a single
unit. For example, a class. Encapsulation also allows data-hiding as the data specified in one
class is hidden from other classes.
Data abstraction is a very important feature of OOPs that allows displaying only the
important information and hiding the implementation details.
Abstract class
Abstract method
An abstract class is a class that consists of abstract methods. These methods are basically
declared but not defined. If these methods are to be used in some subclass, they need to be
exclusively defined in the subclass.
31. Can you create an instance of an abstract class?
No. Instances of an abstract class cannot be created because it does not have a complete
implementation. However, instances of subclass inheriting the abstract class can be created
Virtual functions are functions that are present in the parent class and are overridden by the
subclass. These functions are used to achieve runtime polymorphism.
Pure virtual functions or abstract functions are functions that are only declared in the base
class. This means that they do not contain any definition in the base class and need to be
redefined in the subclass.
The super keyword is used to invoke the overridden method, which overrides one of its
superclass methods. This keyword allows to access overridden methods and also to access
hidden members of the superclass
friend Function
A friend function can access the private and protected data of a class. We declare a friend
function using the friend keyword inside the body of the class.
Virtual Functions
A virtual function is a member function which is declared within a base class and is re-
defined(Overriden) by a derived class.
46. What is exception handling?
Error Exception
Errors are problems that should not be Conditions that an application might try to
encountered by applications catch
48. What is a try/ catch block?
A try/ catch block is used to handle exceptions. The try block defines a set of statements that
may lead to an error. The catch block basically catches the exception.
A finally block consists of code that is used to execute important code such as closing a
connection, etc. This block executes when the try block exits. It also makes sure that finally
block executes even in case some unexpected exception is encountered.
A parameter is a variable used during the declaration of the function or subroutine, and
arguments are passed to the function body, and it should match with the parameter defined.
There are two types of Arguments.
Call by Value – Value passed will get modified only inside the function, and it returns
the same value whatever it is passed into the function.
Call by Reference – Value passed will get modified in both inside and outside the
functions and it returns the same or different value.
Tokens
A token is the smallest element of a program that is meaningful to the compiler. Tokens can
be classified as follows:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
The base class is the most generalized class, and it is said to be a root class.
The superclass is the parent class from which another class inherits.
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 Bindin
11) What is the difference between call by value and call by reference in C?
Description When a copy of the value is passed to When a copy of the value is passed to
the function, then the original value is the function, then the original value is
not modified. modified.
Safety In this case, actual arguments remain In this case, actual arguments are not
safe as they cannot be modified. reliable, as they are modified.
Arguments The copies of the actual arguments are The addresses of actual arguments are
passed to the formal arguments. passed to their respective formal
arguments.
calloc() malloc()
Initialization It initializes the content of the It does not initialize the content of
memory to zero. memory, so it carries the garbage
value.
Return value It returns a pointer pointing to the It returns a pointer pointing to the
allocated memory. allocated memory.
C C++
In C language, data and functions are the In the C++ language, both data and functions
free entities. are encapsulated together in the form of a
project.
C does not support the data hiding. C++ supports data hiding. Therefore, the data
Therefore, the data can be used by the cannot be accessed by the outside world.
outside world.
C supports neither function nor operator C++ supports both function and operator
overloading. overloading.
In C, the function cannot be implemented In the C++, the function can be implemented
inside the structures. inside the structures.
Reference variables are not supported in C C++ supports the reference variables.
language.
C language does not support the virtual and C++ supports both virtual and friend functions.
friend functions.
In C, scanf() and printf() are mainly used C++ mainly uses stream cin and cout to
for input/output. perform input and output operations.
1 stdio.h
Input/Output functions
Sr.No. Header Files & Description
2 conio.h
Console Input/Output functions
3 stdlib.h
General utility functions
4 math.h
Mathematics functions
5 string.h
String functions
6 ctype.h
Character handling functions
One of the very strong reasons why C programming language is so popular and used so
widely is the flexibility of its use for memory management. Programmers have opportunities
to control how, when, and where to allocate and deallocate memory. Memory is allocated
statically, automatically, or dynamically in C programming with the help
of malloc and calloc functions.
Bitwise Operators
Operator Description
| Bitwise OR Operator
AND Operator
00001100
& 00011001
_________
OR Operator
00001100
| 00011001
_________
00001100
^ 00011001
_________
~ 00100011
__________
11011100
2's Complement
2's Complement :
11011011
+ 1
_________
11011100
Shift Operators
The right shift operator shifts all bits towards the right by a certain number
of specified bits. It is denoted by >>.
When we shift any number to the right, the least significant bits are discarded, while
the most significant bits are replaced by zeroes.
The left shift operator shifts all bits towards the left by a certain number of specified
bits. It is denoted by <<.