Class and Object

Last Updated :
Discuss
Comments

Question 1

What does the this pointer in C++ represent?

  • A

    Pointer to class name

  • B

    Pointer to current object

  • C

    Pointer to base class

  • D

    Pointer to constructor

Question 2

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. CPP
#include<iostream>
using namespace std;

class Test
{
    static int x;
    int *ptr;
    int y;
};

int main()
{
    Test t;
    cout << sizeof(t) << " ";
    cout << sizeof(Test *);
}
  • A
    12 4
  • B
    12 12
  • C
    8 4
  • D
    8 8

Question 3

What is the correct way to dynamically create an object in C++?

  • A

    ClassName obj = new ClassName();

  • B

    ClassName *obj = new ClassName();

  • C

    ClassName obj();

  • D

    ClassName = new object();

Question 4

Which access specifier allows members to be accessed only within the class?

  • A

    public

  • B

    protected

  • C

    private

  • D

    none of them

Question 5

What will be the size of an empty class in C++?

  • A

    0

  • B

    1

  • C

    4

  • D

    compile time error

Question 6

A member function can always access the data in __________ , (in C++).
  • A
    the class of which it is member
  • B
    the object of which it is a member
  • C
    the public part of its class
  • D
    the private part of its class

Question 7

What will be the output?

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

  • A

    0

  • B

    Garbage Value

  • C

    Compiler Error

  • D

    None of the Above

There are 7 questions to complete.

Take a part in the ongoing discussion