• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Class and Object

Question 11

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

  • Must be declared in public section of class.

  • Virtual function can be static.

  • Virtual function should be accessed using pointers.

  • Virtual function is defined in base class.

Question 12

Which of the following, in C++, is inherited in a derived class from base class ?
  • constructor
  • destructor
  • data members
  • virtual methods

Question 13

Which of the following is true about the following program CPP
#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;
}
Contributed by Pravasi Meet
  • Compiler Error: Cannot have two objects with same class name
  • Compiler Error in Line "::t.get();"
  • Compiles and runs fine

Question 14

What is the difference between struct and class in C++?
  • All members of a structure are public and structures don\'t have constructors and destructors
  • Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
  • All members of a structure are public and structures don\'t have virtual functions
  • All of the above

Question 15

Which of the following is not a member of class?
  • Static function
  • Friend function
  • Const function
  • Virtual function

Question 16

Predict the output of following C++ program CPP
#include<iostream>
using namespace std;
 
class Empty {};
 
int main()
{
  cout << sizeof(Empty);
  return 0;
}
  • A non-zero value
  • 0
  • Compiler Error
  • Runtime Error

Question 17

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
  • (1)
  • (2), (4)
  • (2), (3), (4)
  • (4)

There are 17 questions to complete.

Last Updated :
Take a part in the ongoing discussion