You are on page 1of 6

1. What is OOP?

Ans: it is stand for object oriented programming .it is use to develop software.in oop a programm is
designed by using objects. It is easy and flexible approach to designing and organizing programming. The
whole system is divided into a set of object.

2. What is the difference between OOP and Sequential


Programming?
Object Oriented Programming:
Object oriented programming can be defined as a programming model which is based upon
the concept of objects. Objects contain data in the form of attributes and code in the form of
methods. I

A sequential programming is when the algorithm to be solved consists of operations


one after the other, where there are no sentences that are repeated or you do not have to do
alternative operations. For example: The alarm sounds. You wake up. You brush your teeth.

3. Explain Access Specifiers in detail with examples?


Ans: Public Access: the Public specifier is used to allow the acess of class members outside the classas
well as within the class.the members of the class that follow the public specifier can be access from inside
and outside the class , normally member function s are declared as public it is because the member
function provide the services to access data from object. This set of the services from the public interface
of the class.

For example

Class Public Access

// public access modifier

public:

int x; // Data Member Declaration

void display(); // Member Function declaration

}
Private Access: Private keyword, means that no one can access the class members declared private,
outside that class. If someone tries to access the private members of a class, they will get a compile time
error. By default class variables and member functions are private.

For example

class Private Access

// private access modifier

private:

int x; // Data Member Declaration

void display(); // Member Function declaration

Protected Access: Protected access specifier is a stage between private and public access .it is used to
allow the access of class members and friend function of that class .

For example

class Protected Access

// protected access modifier

protected:

int x; // Data Member Declaration

void display(); // Member Function declaration

5. Explain Pointers & New Keyword with examples?


Ans: Pointers are the most important feature of cpp.these are used to create and manipulate
dynamic data structures. Such as linked lists, stacks, queues

The new operator is an operator which denotes a request for memory allocation on the Heap. If
sufficient memory is available, new operator initializes the memory and returns the address of
the newly allocated and initialized memory to the pointer variable
6. What is the difference between Constructor & Destructor
explains minimum 10 differences in tabular form?
Difference between Constructor and Destructor in C++ :
S.N

O CONSTRUCTOR DESTRUCTOR

Constructor helps to initialize the Whereas destructor is used to

1. object of a class. destroy the instances.

It is declared as( argument if any Whereas it is declared –class

2. ){constructer body } name {destructor body

Constructor can either accept the

3. arguments or not. While it can’t have any argument.

A constructor is called when the

instance or object of the class is It is called while object of the

4. created. class is freed or deleted.

Constructor is used to allocate

the memory to an instance or While it is used to deallocate the

5. object. memory of an object of a class.

6. Constructor can be overloaded. While it can’t be overloaded.

Here, it’s name is also same as

The constructor’s name is same the class name preceded by tiled

7. as the class name. (~) operator.

7. What is Function Overloading?


Ans: Function overloading is a C++ programming feature that allows us to have more than one
function having same name but different parameter list, when I say parameter list, it means the
data type and sequence of the parameters, for example the parameters list of a function
myfuncn(int a, float b) is (int, float). which is different from the function myfuncn (float
a, int b) parameter list (float, int).

8. Define Setter Getter and why we need them, explain


them with examples?
Getters and setters are used to protect your data, particularly when creating classes. For each
instance variable, a getter method returns its value while a setter method sets or updates its
value. ... The getter method returns the value of the attribute. The setter method takes a
parameter and assigns it to the attribute.

Why use getters and setters?


Getters and setters allow you to control how important variables are accessed and updated in
your code. For example, consider this setter method:

public void setNumber(int number) {


if (number < 1 || number > 10) {
throw new IllegalArgumentException();
}
This number = num;
}
By using the setNumber method, you can be sure the value of number is always between 1
and 10. This is much better than updating the number variable directly:
obj.number = 13;

9. What is Constructor Overloading?


Ans: A single class may have multiple constructer, like function overloading it is known as constructer
over loading each constructer is defined in a class with different set of parameters.

10. Explain all types of Constructor?

Types of Constructors
There are three types of constructors: Default, No-arg constructor and
Parameterized.
Default constructor
If you do not implement any constructor in your class, Java compiler inserts a
default constructer into your code on your behalf. This constructor is known as
default constructor. You would not find it in your source code(the java file) as it
would be inserted into the code during compilation and exists in .class file

no-arg constructor:
Constructor with no arguments is known as no-arg constructor. The signature
is same as default constructor; however body can have any code unlike default
constructor where the body of the constructor is empty.

Constructor with arguments (or you can say parameters) is known


as Parameterized constructor

Example: parameterized constructor

In this example we have a parameterized constructor with two


parameters id and name. While creating the objects obj1 and obj2 I have passed two
arguments so that this constructor gets invoked after creation of obj1 and obj2.

11. What is the use of Scope Resolution operator (::) in OOP?

The scope resolution operator ( :: ) is used for several reasons. For example: If the


global variable name is same as local variable name, the scope resolution
operator will be used to call the global variable. It is also used to define a function
outside the class and used to access the static variables of class.

12. What is the difference between Structure and


Class?
Difference between Class and Structure

CLASS STRUCTURE

Classes are of reference types. Structs are of value types.


All the reference types are

allocated on heap memory. All the value types are allocated on stack memory.

Allocation of large reference type is

cheaper than allocation of large Allocation and de-allocation is cheaper in value type as

value type. compare to reference type.

Class has limitless features. Struct has limited features.

Class is generally used in large

programs. Struct are used in small programs.

Structure does not contain parameter less constructor or

Classes can contain constructor or destructor, but can contain Parameterized constructor or

destructor. static constructor.

You might also like