Test: Class And Objects - 2


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


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

Which is used to create a pure virtual function ?

Solution:

For making a method as pure virtual function, We have to append ‘=0' to the class or method.

QUESTION: 2

Which of the following is not a correct statement?

Solution:

• Every class containing abstract method must be declared abstract. Correct Declaration is required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated. Correct
• Abstract class does not contain any definition of implementation. Correct
So, option (B) is correct.

QUESTION: 3

What is meant by pure virtual function?

Solution:

As the name itself implies, it have to depend on other class only.

QUESTION: 4

It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.

Solution:

It is possible to define a class within a class termed as nested class. There are two types of nested classes.
1 – Outer class will use argument of inner class.
2 – Inner and outer class are independent to each other.(different argument)
So, optioin (A) is correct.

QUESTION: 5

Where does the abstract class is used?

Solution:
QUESTION: 6

Which of the following, in C++, is inherited in a derived class from base class ?

Solution:

• Data members in C++ is inherited in a derived class from base class
• Constructor is a member function of a class which initializes objects of a class. In C++,Constructor is automatically called when object(instance of class) create.It is special member function of the class.
• Destructor is a member function which destructs or deletes an object.
• Virtual methods is a method which is redefined(Over-riden) in derived class.
So, option (C) is correct.

QUESTION: 7

Pick out the correct statement.

Solution:

Destructors are automatically invoked when a object goes out of scope or when a dynamically allocated object is deleted. Inheritance does not change this behavior. This is the reason a derived destructor cannot invoke its base class destructor.

QUESTION: 8

What is the difference between struct and class in C++?

Solution:
QUESTION: 9

Which operator is used to declare the destructor?

Solution:
QUESTION: 10

What is the output of the program?

class Test {
    int x; 
};
int main()
{
  Test t;
  cout << t.x;
  return 0;
}

Solution:

In C++, the default access is private. Since x is a private member of Test, it is compiler error to access it outside the class.

QUESTION: 11

Which interface decides determines how your class will be used by other program?

Solution:

If we invoked the interface as public means, We can access the program from other programs also.

QUESTION: 12

Assume that an integer and a pointer each takes 4 bytes. Also, assume that there is no alignment in objects. Predict the output following program.

#include<iostream>
using namespace std;
class Test
{
    static int x;
    int *ptr;
    int y;
};
 
int main()
{
    Test t;
    cout << sizeof(t) << " ";
    cout << sizeof(Test *);
}

Solution:

For a compiler where pointers take 4 bytes, the statement “sizeof(Test *)” returns 4 (size of the pointer ptr).
The statement “sizeof(t)” returns 8. Since static is not associated with each object of the class, we get (8 not 12).

QUESTION: 13

How many ways of reusing are there in class hierarchy?

Solution:

Class hierarchies promote reuse in two ways. They are code sharing and interface sharing.

QUESTION: 14

A member function can always access the data in __________ , (in C++).

Solution:

A member function can access it’s class member variables, irrespective of the access specifier in which the member variable is declared.So, a member function can always access the data in the class of which it is a member.
So, option (A) is correct.

QUESTION: 15

What will happen when introduce the interface of classes in a run-time polymorphic hierarchy?

Solution:
QUESTION: 16

Which of the following is not correct (in C++) ?
1. Class templates and function templates are instantiated in the same way
2. Class templates differ from function templates in the way they are initiated
3. Class template is initiated by defining an object using the template argument
4. Class templates are generally used for storage classes

Solution:

In C++ class template and function template are similar in the way the are initiated.
Class template are not used for storage class. Class templates and function templates are instantiated in the same way and Class template is not initiated by defining an object using the template.
So (2), (3), (4) are not correct in C++.
So, option (C) is correct.

QUESTION: 17

What is the use of clog?

Solution:

Clog is an object of class ostream that represents the standard logging stream. It is associated with the cstdio stream stderr, like cerr.

QUESTION: 18

Which of the following is a correct statement?

Solution:

• Composition is a strong type of association between two classes with full ownership. Correct.
• Composition is a strong type of association between two classes with partial ownership. Incorrect
• Composition is a weak type of association between two classes with partial ownership. Incorrect
• Composition is a weak type of association between two classes with strong ownership. Incorrect
So, option (A) is correct.

QUESTION: 19

Which operator is used to create the user-defined streams in c++?

Solution:

We can make user-defined types with streams by overloading the insertion operator (<<) to put objects into streams and the extraction operator (>>) to read objects from streams.

QUESTION: 20

When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass.

Solution:

• When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass overrides the method in the superclass.
• Overloading allows different methods to have same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both. Overloading is related to compile time (or static) polymorphism..
• Friend Class A friend class can access private and protected members of other class in which it is declared as friend..
• The capability of a class to derive properties and characteristics from another class is called Inheritance.
So, option (D) is correct.

Related tests