Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Object Oriented Programming Questions
Description: Here are few questions of OOPS for Students who study computer sciences as compulsory or optional subject at BS levels. Notes that match the Students level of concepts !
Description: Here are few questions of OOPS for Students who study computer sciences as compulsory or optional subject at BS levels. Notes that match the Students level of concepts !
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
BS COMPUTER SCIENCE
SUBJECT
:
OOPS
Section A
Question 1(a):
Answer:
Template :
Template are the mechanism by which c++ implement genetic concept
...
Template is a blue print or formula for creating a generic class or function
...
class template is
an alternative of function overloading as once class is declared it can be used for different data types
to have a various related result
...
Syntax:
template < class T1, class T2,
...
:
DESTRUCTOR
Destructor is a special
member of a class used to
deallocate memory for a
class
...
to execute some code at the
time of it destruction
...
They are called in reverse
order
...
The memory deallocate by
destructor can be further
located at the other resources
used in the program
...
There is always a single
destructor in a class
...
It can not be overloaded
...
Destructor have the same
name as the class but have
a tild (~) symbol in a name
...
e c++ and
high level language i
...
Destructors are not supported
in Java
...
Destructors have no
parameters or arguments as
it only deallocate memory for
an object
...
It has no such concept
...
The return address is located where subroutine was called
...
It terminate the execution of the function and transfer the
control back to the calling function (or to the operating system if transfer control from main()
...
It return value for only void
function for non void function it may or may not return value
...
#include
...
4
...
{
6
...
Public:
8
...
{
10
...
Cout<<” constructor \n”;
12
...
}
14
...
{ 16
...
Cout<<”Destructor \n”;
18
...
20
...
Int main()
22
...
Method m();
24
...
}
26
...
Question 1(b):
Answer :
Difference Between Class and Object :
Class
1
...
e object
...
object is an instance of class
helps programmers to used
variables and methods inside
class
...
Class once created ,it does not 2
...
allocate memory space to store
values
...
It is declared using keyword
class
...
It is declared using keyword
new
...
Cass is used to bind data as
well as methods in a single
unit
...
Object is a variable of class
...
Class have logical exsistance 5
...
used for some special purpose
...
The new class inherit all the behavior of the original class
...
Derived class:
The new class that inherit the properties and functions of the existing class is known as Derived
class or child class
...
The basic principle of
inheritance is that each subclass share common properties with the class from which it is derived
...
2
...
4
...
Reusebillity:
Inheritance allows the developers to reuse the existing code in many situations
...
Saves Time And Efferts:
Inheritance saves a lot of time and effort to write the same classes again
...
3
...
This class can be used in a new application
without compiling it again
...
Program:
1
...
using namespace std;
3
...
o(); B
...
This operator has
many uses in c++
...
Uses:
Scope Resolution Operator is used for:
1
...
2
...
3
...
4
...
5
...
6
...
Program:
1
...
3
...
int main()
5
...
Int num=2;
7
...
std::Cout<<”local variable=”<<::num;
9
...
In Hierarchical inheritance all the features that are common in derived classes are
included in the base class
...
}
Class first_derived_class : public base _class{
...
}
Class third _derived_class: public base_class{
...
All derived classes have there own members as well as there base class
members
...
Program using Hierarchical Inheritance:
//Hierarchical inheritance
1
...
using namespace std;
3
...
class A //single base class
5
...
Public:
7
...
void getdata()
9
...
11
...
13
...
15
...
17
...
19
...
}
22
...
24
...
26
...
28
...
31
...
33
...
35
...
};
class C: public A // derived from base class A
{
public :
void sum()
{
cout<<”\n the sum of X and Y is :”<
void subtrction()
37
...
39
...
41
...
};
43
...
int main()
45
...
C obj1; //object of derived class C
47
...
D obj3;//object of derived class D 49
...
obj1
...
obj1
...
obj2
...
obj2
...
obj3
...
obj3
...
57
...
59
...
Function Overriding allows the user to use same name for calling the member function of
different class
...
However, the function of base class can be accessed by using
scope resolution operator
...
Program:
1
...
using namespace std;
3
...
{
5
...
void display()
7
...
cout<<”Function of parent class”;
9
...
};
11
...
{
13
...
void display()
15
...
cout<<”function of derived class”;
17
...
};
19
...
{
22
...
obj
...
return 0;
25
...
The
derived class can access the public, protected and private member of base class but the object
of derived class can not access the public , private and protected members of the base class
...
#include
2
...
Class parent 4
...
6
...
Int a; 8
...
Int b;
10
...
Int c;
12
...
};
14
...
{
16
...
Void in()
18
...
Cout<<”Enter a”;
20
...
Cout<<”Enter b”;
22
...
{
24
...
{ 26
...
Cout<<”a=”< ...
}
30
...
32
...
{
34
...
Obj
...
Obj
...
getch() 38
...
}
Question 1(j):
Answer:
DIFFERENCE BETWEEN USER DEFINED FUNCTION AND BUILT IN FUNCTION:
User Defined Function
Built in Function
1
...
1
...
2
...
2
...
3
...
3
...
4
...
e
main()
...
Execution does not begin from
these functions
...
User can change the name of
the user defined functions
...
Name once given to a function
by the developer cannot be
changed by the user
...
User defined these functions
to perform there required
specific task
...
The tasks these to perform are
decided by the system or
developer we can say
...
#include
2
...
//declaration of user defined
function 4
...
{
6
...
int main()
8
...
greet();//calling function
10
...
return 0;
12
...
#include
2
...
#include
4
...
{
6
...
number=36;
8
...
10
...
return 0;}
Examples:
Name() etc
...
SECTION B
Question 3:
Answer
:
Constructor:
The member function that can have the same name as the class name is called constructor
...
Constructor has no return type that mean it
cannot return any value
...
Constructor Overloading:
The process of declaring multiple constructor with same name but different parameter is known
as Constructor Overloading
...
Numbers of parameters
2
...
Sequence of parameters
Important concept of constructor overloading:
1
...
2
...
3
...
4
...
5
...
6
...
Program:
// program using constructor
1
...
using namespace std;
3
...
class person{
5
...
int age;
7
...
public;
9
...
11
...
13
...
person(int a)
15
...
Age=a
17
...
19
...
{
21
...
}
23
...
Int main()
25
...
Person person1, person2(45);
27
...
cout<<”person1”<
cout<<”person2 age”<
31
...
}
Explaination:
In above there are two constructors person() and person (int a)
...
The constructor person() has no argument ,so is called when no argument is passed to the object
and person(int a) is called when passed value to the object (I
...
Question 6:
Answer :
Object Oriented Programming:
Object oriented Programming (OOPs) is a technique in which program are written on
the basis of object and is associated with other concepts like class ,inheritance encapsulation
,abstraction and polymorphism
...
c++ and Java are the most popular object oriented programming
...
It is the basic unit of oops that uses different data
member and member function to perform different tasks
...
Class:
Class is a collection of object with same properties and function
...
It is
used as a model for creating object of the same type
...
A
class declaration specifies the variable and function common to all the object of the class
...
Syntax:
Class identifier
{
Body
};
Inheritance:
A programming technique that is used to reuse an existing class to built a new class is called
Inheritance
...
Base class:
Class used to create a new class is called parent class or base class
...
Types:
1
...
3
...
Single inheritance
Multiple inheritance
Hierarchical inheritance
Hybrid inheritance
Advantages:
1
...
3
...
It allows programmers’ to extent and reuse a code
...
The user does not have to know the exact type of object in advance
...
It is called late binding or dynamic binding
...
Abstraction:
Abstraction only refers to showing only essential feature of application an hiding the
details
...
This can be done using access
specified
...
Encapsulation is all about binding data variable and
functions in a class
...
Data hiding is the process
that ensure the exclusive data
access to the class member and
protect object integrity by
preventing the intended and
non intended changes
...
2
...
It focus on hiding the
while hiding the complexity
...
3
...
3
...
4
...
4
...
Program: class
Base { int
num; public:
void read();
void print();
};
void Base::read()
{
cout<<”enter the value”;
}
void Base::print(){ cout<<”the
value
is”<
Int main()
{
Base obj;
Obj
...
print();
return 0;
Program:
class Encapsulation
{
Private: int
num;
public: int
set(int a)
{
num=a;}
int get()
{
}
Cout<
set(5);
}
Question 4:
Answer :
Difference Between inline Function and Simple Function :
Inline Function
Simple Function
1
...
1
...
2
...
2
...
3
...
No repeation of the code of
repeated at each function call
...
4
...
A program can be small or
declared as inline function
...
5
...
5
...
Program:
#include
Using namespace std;
inline int cube(int n)
{
Return n*n*n;
}
void main()
{
Cout<
}
Program :
#include
Using namespace std;
int main()
{
Int cube();
Cube(3);
return 0;
}
int cube()
{ int
X,Y;
cout<<”enter a number for
cube :”; cin>>X;
Y=cube(X);
Cout<
Question 2:
Answer :
Difference Between parameterized and Non parameterized Constructor:
Parameterized Constructor
Non Parameterized Constructor
1
...
1
...
2
...
2
...
3
...
3
...
4
...
Syntax: data type
function name()
{
Body of function
}
Program:
#include
Using namespace std;
Void max (int a,int b)
Void main()
{
Int X,Y;
Cout<<”enter two numbers”;
Cin>>X>>Y;
Max(X,Y);
getch();
}
Void max(int a ,int b)
{
if(a>b)
cout<<”maximum number
is”<cout<<”maximum number
is”<}
Program:
#include
Using namespace std;
Void show (void)
Void main()
{
Show();
getch();
}
Void show()
{
Cout<<”c++
programming”<
Title: Object Oriented Programming Questions
Description: Here are few questions of OOPS for Students who study computer sciences as compulsory or optional subject at BS levels. Notes that match the Students level of concepts !
Description: Here are few questions of OOPS for Students who study computer sciences as compulsory or optional subject at BS levels. Notes that match the Students level of concepts !