C++: Classes And Objects Questions 4

Q.16.
What is the output of this program?

Note:Includes all required header files
class Test
{
int x;
};

int main()
{
Test t;
cout << t.x;
return 0;
}
A. 0
B. Garbage value
C. Runtime error
D. Complier error

Q.17.
What will be the output of the following program?

#include<iostream>
using namespace std;
class course
{
int x, y;
public:
set(int xx)
{
x = ++xx;
}
void Display()
{
cout<< –x << ” “;
}
};
int main()
{
course obj;
obj.set(20);
obj.Display();
obj.Display();
return 0;
}

A. 20 20
B. 21 20
C. 20 19
D. Error

Q.18.
What is the output of this program?

Note:Includes all required header files
using namespace std;

class Empty {};

int main()
{
cout << sizeof(Empty);
return 0;
}

A. A non-zero value.
B. 0
C. Compiler Error
D. Runtime Error


Q.19.
What will be the output of this program?

Note:Includes all required header files
using namespace std;

class sample
{
int x;
}

int main()
{
sample obj;
obj.x=100;
cout<<“x=”<< obj.x;
}
A. 10
B. 100
C. Error
D. None of the above


Q.20.
What will be the output of this program?

Note:Includes all required header files
using namespace std;
//Empty class
class test
{
};

int main()
{
test testObj;
cout<<“size =”<< sizeof(testObj);
return 0;
}
A. Error
B. size =Garbage
C. size =1
D. Compile but no output