Vous êtes sur la page 1sur 5

C++ Objective Question Praveen Kumar Chandaliya

1. }
#include<iostream>
#include<conio.h> 3.
using namespace std; #include<iostream>
class Sample #include<conio.h>
{ using namespace std;
public : class Sample
{
Sample() private :
{ int x;
cout<<"\n CONSTR"; public :
}
~Sample() Sample(int n)
{ {
cout<<"\n DEST "; x = n;
}
}; }
int main() void show_data()
{ {
Sample s; cout<<"x="<<x;
}
} };
Ans : Private Con. int main()
2. {
#include<iostream> Sample s;
#include<conio.h> s.show_data();
using namespace std; }
class Sample 4.
{ #include<iostream>
private : #include<conio.h>
int x; using namespace std;
public : class Sample
{
Sample(int n) private :
{ int x;
x = n; public :
cout<<"\n CONSTR";
} Sample(int n)
~Sample() {
{ x = n;
cout<<"\n DEST ";
} }
}; Sample(Sample s)
int main() {
{ x = s.x;
Sample s; }
void show_data()

1|Page www.javapadho.com
C++ Objective Question Praveen Kumar Chandaliya

{ s2.show_data();
cout<<"x="<<x; getch();
} }
~Sample(int n)
{ Ans : Invalid copy constructor
cout<<"\n Destroyed";
} 6.
}; #include<iostream>
int main() #include<conio.h>
{ using namespace std;
Sample s1(3); class Sample
Sample s2 = s1; {
s.show_data(); private :
} int x;
Ans : Destructor not arg type possible public :

5. #include<iostream> Sample(int n)
#include<conio.h> {
using namespace std; x = n;
class Sample
{ }
private : Sample(Sample &s)
int x; {
public : x = s.x;
}
Sample(int n) void show_data()
{ {
x = n; cout<<"x="<<x;
}
} ~Sample()
Sample(Sample s) {
{ cout<<"\n Destroyed";
x = s.x; }
} };
void show_data() int main()
{ {
cout<<"x="<<x; Sample s1(3);
} Sample s2 = s1;
~Sample() s2.show_data();
{ getch();
cout<<"\n Destroyed"; }
}
}; Ans : x=3
int main()
{
Sample s1(3);
Sample s2 = s1; 7.

2|Page www.javapadho.com
C++ Objective Question Praveen Kumar Chandaliya

#include<iostream> {
#include<conio.h> cout<<"in Destructor"<<endl;
using namespace std; }
class item };
{
static int count; int main()
public : {
item() item obj1;
{
count++; getch();
} }
int getcount()
{ In constructor
return count; In destructor
}
int getcadd()
{
return count; 9. Error in this program.
} #include<iostream.h>
}; class Number
int item ::count=0; {
int main() private :
{ int a;
item obj1; int b;
cout<<obj1.getcount()<<" "; public:
item obj2; void set_data(int x,int y)
cout<<obj2.getcount()<<" "; {
cout<<obj1.getcadd()<<" "; a =x;
cout<<obj2.getcadd()<<" "; b =y;
getch(); }
} };
int main()
Ann : 1 2 2 2 { set_data(10,20);
}
8.
#include<iostream> 10.Error in this program.
#include<conio.h> #include<iostream.h>
using namespace std; class Ntumber
class item {
{ private :
int x; int a;
public : int b;
item() public:
{ void set_data(int x,int y)
cout<<"in constructor"<<endl; {
} a =x;
~item() b =y;

3|Page www.javapadho.com
C++ Objective Question Praveen Kumar Chandaliya

} n.show_data();
}; getch();
int main() }
{ Number n
n.set_data(10,20,30); Ans : in class not initialized
}
13.
11. class Number
class Test {
{ public:
private : Number()
static int count; {
public: a=10;
static void show_data() }
{ void set_data(char c)
cout<<count++; {
} ch =c;
}; }
int Test ::count=1; void show_data()
int main() {
{ Test t; cout<<a<<" "<<ch;
t.show_data(); }
} private:
int a;
12. char ch;
#include<iostream> };
#include<conio.h> int main()
using namespace std; {
class Number Number n;
{ n.set_data('A');
public: n.show_data();
void set_data(char c) getch();
{ }
ch =c;
} 14.
void show_data() Which of the following keyword support
{ dynamic method resolution?
cout<<a<<" "<<ch; a) abstract
} b) virtual
private: c)dynamic
int a =10; d)typeid.
char ch;
} Ans : virtual
int main() 15
{ What is the implicit pointer that is passed as
Number n; first argument for non-static member functions?
n.set_data('A');

4|Page www.javapadho.com
C++ Objective Question Praveen Kumar Chandaliya

Ans :this

16.
Which of the following operator cannot be
overloaded?
a) = (assignment operator)
b) ==(equality operator)
c) -> (arrow operator)
d) :: (scope resolution operator)

17. How do we declare an abstract class?

Ans . By providing at least one pure virtual


function.

18. How may copies of class static member


are shared between objects of the class?

Ans : Static member are not associated with


objects,but are associated with the class. A copy of
the static member is shared by all objects of a class.

19.
What is the default inheritance type when no
access specifier is explicitly specified for the base
class?
Ans : private

20.
Destructor can be overloaded.
Ans : false
Destructor cannot take any arguments (ther
can be only one destructor for a class).

5|Page www.javapadho.com

Vous aimerez peut-être aussi