Test: Class And Objects - 1


10 Questions MCQ Test Learn to Program with C++: Beginner to Expert | Test: Class And Objects - 1


Description
This mock test of Test: Class And Objects - 1 for Back-End Programming helps you for every Back-End Programming entrance exam. This contains 10 Multiple Choice Questions for Back-End Programming Test: Class And Objects - 1 (mcq) to study with solutions a complete question bank. The solved questions answers in this Test: Class And Objects - 1 quiz give you a good mix of easy questions and tough questions. Back-End Programming students definitely take this Test: Class And Objects - 1 exercise for a better result in the exam. You can find other Test: Class And Objects - 1 extra questions, long questions & short questions for Back-End Programming on EduRev as well by searching above.
QUESTION: 1

What does your class can hold?

Solution:

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

QUESTION: 2

Predict the output of following C++ program

#include<iostream>
using namespace std;
  
class Empty {};
  
int main()
{
  cout << sizeof(Empty);
  return 0;
}

Solution:

#include<iostream>
using namespace std;
  
class Empty {};
  
int main()
{
  cout << sizeof(Empty);
  return 0;
}
Output : 1

Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses. 

QUESTION: 3

How many kinds of classes are there in c++?

Solution:

There are two kinds of classes in c++. They are absolute class and concrete class.

QUESTION: 4

Which of the following is true?

Solution:

Every object maintains a copy of non-static data members. For example, let Student be a class with data members as name, year, batch. Every object of student will have its own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find out grades or any other method.

QUESTION: 5

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

Solution:

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

QUESTION: 6

Which of the following is true about the following program

#include <iostream>
class Test
{
public:
    int i;
    void get();
};
void Test::get()
{
    std::cout << "Enter the value of i: ";
    std::cin >> i;
}
Test t;  // Global object
int main()
{
    Test t;  // local object
    t.get();
    std::cout << "value of i in local t: "<<t.i<<'n';
    ::t.get(); 
    std::cout << "value of i in global t: "<<::t.i<<'n';
    return 0;
}

Solution:

The above program compiles & runs fine. Like variables it is possible to create 2 objects having same name & in different scope.

QUESTION: 7

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

Solution:
QUESTION: 8

Which of the following is not correct for virtual function in C++ ?

Solution:

Virtual function is can’t be static in C++. So, option (B) is correct.

QUESTION: 9

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

Solution:
QUESTION: 10

Which of the following cannot be passed to a function in C++ ?

Solution:

Header file can not be passed to a function in C++. While array, constant and structure can be passed into a function.
So, option (D) is correct.

Related tests