Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

When struct is used instead of the keyword class means, what will happen in the program?


  1.    access is public by default
  2.    access is private by default
  3.    access is protected by default
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> access is public by default

None.


Question 2.

Constructors are used to


  1.    initalize the objects
  2.    construct the data members
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> initalize the objects

Once the object is declared means, the constructor are also declared by default.


Question 3.

The fields in the class in c++ program are by default


  1.    protected
  2.    private
  3.    public
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> private

None.


Question 4.

Which of the following is a valid class declaration?


  1.    class A { int x; };
  2.    class B { }
  3.    public class A { }
  4.    object A { int x; };
 Discuss Question
Answer: Option A. -> class A { int x; };

None.


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class CDummy
4.
{
5.
public:
6.
int isitme (CDummy& param);
7.
};
8.
int CDummy::isitme (CDummy& param)
9.
{
10.
if (&param == this)
11.
return true;
12.
else
13.
return false;
14.
}
15.
int main ()
16.
{
17.
CDummy a;
18.
CDummy *b = &a;
19.
if (b->isitme(a)) {
20.
cout << "execute";
21.
}
22.
else
23.
{
24.
cout<<"not execute";
25.
}
26.
return 0;
27.
}
  1.    execute
  2.    not execute
  3.    none of the mentioned
  4.    both a & b
 Discuss Question
Answer: Option A. -> execute

In this program, we are just pointing the pointer to a object and printing execute if it is correctly pointed.
Output:
$ g++ class1.cpp
$ a.out
execute


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class rect
4.
{
5.
int x, y;
6.
public:
7.
void val (int, int);
8.
int area ()
9.
{
10.
return (x * y);
11.
}
12.
};
13.
void rect::val (int a, int b)
14.
{
15.
x = a;
16.
y = b;
17.
}
18.
int main ()
19.
{
20.
rect rect;
21.
rect.val (3, 4);
22.
cout
  1.    rect area:12
  2.    rect area: 12
  3.    rect area:24
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> rect area: 12

In this program, we are calculating the area of rectangle based on given values.
Output:
$ g++ class.cpp
$ a.out
rect area: 12


Question 7.

Which is used to define the member of a class externally?


  1.    :
  2.    ::
  3.    #
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> ::

None.


Question 8.

Which other keywords are also used to declare the class other than class?


  1.    struct
  2.    union
  3.    object
  4.    both a & b
 Discuss Question
Answer: Option D. -> both a & b

Struct and union take the same definition of class but differs in the access techniques.


Question 9.

What does your class can hold?


  1.    data
  2.    functions
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

The classes in c++ are used to manipulate both data and functions.


Question 10.

How many specifiers are present in access specifiers in class?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option C. -> 3

There are three types of access specifiers. They are public, protected and private.


Latest Videos

Latest Test Papers