Back-End Programming Exam  >  Back-End Programming Tests  >  Learn to Program with C++: Beginner to Expert  >  Test: Class And Objects - 2 - Back-End Programming MCQ

Test: Class And Objects - 2 - Back-End Programming MCQ


Test Description

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

Test: Class And Objects - 2 for Back-End Programming 2024 is part of Learn to Program with C++: Beginner to Expert preparation. The Test: Class And Objects - 2 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Class And Objects - 2 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Class And Objects - 2 below.
Solutions of Test: Class And Objects - 2 questions in English are available as part of our Learn to Program with C++: Beginner to Expert for Back-End Programming & Test: Class And Objects - 2 solutions in Hindi for Learn to Program with C++: Beginner to Expert course. Download more important topics, notes, lectures and mock test series for Back-End Programming Exam by signing up for free. Attempt Test: Class And Objects - 2 | 20 questions in 40 minutes | Mock test for Back-End Programming preparation | Free important questions MCQ to study Learn to Program with C++: Beginner to Expert for Back-End Programming Exam | Download free PDF with solutions
Test: Class And Objects - 2 - Question 1

Which is used to create a pure virtual function ?

Detailed Solution for Test: Class And Objects - 2 - Question 1

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

Test: Class And Objects - 2 - Question 2

Which of the following is not a correct statement?

Detailed Solution for Test: Class And Objects - 2 - Question 2

• 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.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Class And Objects - 2 - Question 3

What is meant by pure virtual function?

Detailed Solution for Test: Class And Objects - 2 - Question 3

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

Test: Class And Objects - 2 - Question 4

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

Detailed Solution for Test: Class And Objects - 2 - Question 4

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.

Test: Class And Objects - 2 - Question 5

Where does the abstract class is used?

Test: Class And Objects - 2 - Question 6

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

Detailed Solution for Test: Class And Objects - 2 - Question 6

• 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.

Test: Class And Objects - 2 - Question 7

Pick out the correct statement.

Detailed Solution for Test: Class And Objects - 2 - Question 7

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.

Test: Class And Objects - 2 - Question 8

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

Test: Class And Objects - 2 - Question 9

Which operator is used to declare the destructor?

Test: Class And Objects - 2 - Question 10

What is the output of the program?

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

Detailed Solution for Test: Class And Objects - 2 - Question 10

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.

Test: Class And Objects - 2 - Question 11

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

Detailed Solution for Test: Class And Objects - 2 - Question 11

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

Test: Class And Objects - 2 - 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 *);
}

Detailed Solution for Test: Class And Objects - 2 - Question 12

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).

Test: Class And Objects - 2 - Question 13

How many ways of reusing are there in class hierarchy?

Detailed Solution for Test: Class And Objects - 2 - Question 13

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

Test: Class And Objects - 2 - Question 14

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

Detailed Solution for Test: Class And Objects - 2 - Question 14

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.

Test: Class And Objects - 2 - Question 15

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

Test: Class And Objects - 2 - 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

Detailed Solution for Test: Class And Objects - 2 - Question 16

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.

Test: Class And Objects - 2 - Question 17

What is the use of clog?

Detailed Solution for Test: Class And Objects - 2 - Question 17

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

Test: Class And Objects - 2 - Question 18

Which of the following is a correct statement?

Detailed Solution for Test: Class And Objects - 2 - Question 18

• 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.

Test: Class And Objects - 2 - Question 19

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

Detailed Solution for Test: Class And Objects - 2 - Question 19

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.

Test: Class And Objects - 2 - 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.

Detailed Solution for Test: Class And Objects - 2 - 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 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.

73 videos|7 docs|23 tests
Information about Test: Class And Objects - 2 Page
In this test you can find the Exam questions for Test: Class And Objects - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Class And Objects - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF