Modifier Types
- What is the output of this program?
#include <iostream>
using namespace std;
struct N
{
int k;
char ch;
float p;
void function();
};
void N :: function() {}
struct M
{
public:
int k;
char ch;
float p;
void function();
};
void M :: function() {}
int main()
{
N obj1; M obj2;
obj1.k = obj2.k = 2;
obj1.ch = obj2.ch = 'U';
obj1.p = obj2.p = 5.125;
obj1.function();
obj2.function();
cout << "Value Allocated in memory...";
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We used access specifiers for structures, As we declared all methods as public, The values can be allocated.
- What is the output of this program?
#include <iostream>
using namespace std;
class Employee
{
public:
int IdNo , Salary , bonus ;
protected:
void get()
{
IdNo = 101, Salary = 15000, bonus = 5000;
}
};
class Extra
{
public:
int Gift;
void getGift()
{
Gift = 4000;
}
};
class statement : public Employee, public Extra
{
int GrandTotal, Average;
public:
void display()
{
GrandTotal = (Salary + bonus);
Average = GrandTotal / 2;
cout << GrandTotal << " ";
cout << Average;
}
void setObject()
{
get();
}
};
int main()
{
statement object;
object.setObject();
object.getGift();
object.display();
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
20000 10000
- To which of the following access specifiers are applicable?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The access specifiers can be applicable to the member data and functions because they need to be accessed outside the block.
- What of the following describes protected access specifier?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The variable is visible to its block and to it’s derived class
- How many access specifiers are there in c++?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
There are three access specifiers in c++. They are public, Private and Protected.