C++: Classes And Objects Questions 1

Q.1
Which type of Access Specifier class data member number is?

//a simple class
class test_example
{
int number;
};

a. private
b. public
c. protected
d. default

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

#include <iostream>
using namespace std;
class sample
{
int x;
}

int main()
{
sample obj;
obj.x=100;
cout<<“x=”<<obj.x<<endl;
}

a. x=100
b. Error

Q.3
Which variable(s) is/are accessible in main() function?

class sample
{
private:
int x;
protected:
int y;
public:
int z;
}

a. x
b. y
c. z
d. y and z


Q.4
Write statement to print value of var ?

int var=100;
class sample
{
private:
void showVal(void)
{

}
}

a. cout<<var;
b. cout<<::var;
c. Cannot access var inside class member function.
d. Both a and b

Q.5
Where a protected member can be accessed?

a. Within the same class
b. Outside of the class
c. Within the Derived class
d. Both a and c