a) In Structures, members are public by default whereas, in Classes, they are private by default
b) Structures by default hide every member whereas classes do not
c) Structures cannot have private members whereas classes can have
d) In Structures, members are private by default whereas, in Classes, they are public by default
Answer: a
Explanation: Structure members are public by default whereas class members are private by default. Both of them can have private and public members.
Related Posts
What will be the output of the following C++ code?
#include <iostream>
int const s=9;
int main()
{
std::cout << s;
return 0;
}What will be the output of the following C++ code?
#include <iostream>
int main()
{
const int x;
x = 10;
printf(“%d”, x);
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(int i = 0, int j =0)
{ x = i; y = j; }
int getX() const { return x; }
int getY() {return y;}
};int main()
{
const Point t;
cout << t.getX() << ” “;
cout << t.gety();
return 0;
}Const qualifier can be applied to which of the following?
i) Functions inside a class
ii) Arguments of a function
iii) Static data members
iv) Reference variablesWhat will be the output of the following C++ code?
#include <iostream>
class Test
{
public:
void fun();
};
static void Test::fun()
{
std::cout<<“fun() is static”;
}
int main()
{
Test::fun();
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Test
{
private:
static int count;
public:
Test& fun();
};
int Test::count = 0;
Test& Test::fun()
{
Test::count++;
cout << Test::count << ” “;
return *this;
}
int main()
{
Test t;
t.fun().fun().fun().fun();
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
private:
int x;
public:
A(int _x) { x = _x; }
int get() { return x; }
};
class B
{
static A a;
public:
static int get()
{ return a.get(); }
};
int main(void)
{
B b;
cout << b.get();
return 0;
}
Join The Discussion