• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Class and Object

Question 1

C
class Test {
    int x; 
};
int main()
{
  Test t;
  cout << t.x;
  return 0;
}
  • 0
  • Garbage Value
  • Compiler Error

Question 2

Which of the following is true?
  • All objects of a class share all data members of class
  • Objects of a class do not share non-static members. Every object has its own copy.
  • Objects of a class do not share codes of non-static methods, they have their own copy
  • None of the above

Question 3

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 *);
}
  • 12 4
  • 12 12
  • 8 4
  • 8 8

Question 4

Which of the following cannot be passed to a function in C++ ?
  • Constant
  • Structure
  • Array
  • Header file

Question 5

Which of the following is a correct statement?
  • Composition is a strong type of association between two classes with full ownership.
  • Composition is a strong type of association between two classes with partial ownership.
  • Composition is a weak type of association between two classes with partial ownership.
  • Composition is a weak type of association between two classes with strong ownership.

Question 6

Which of the following is not a correct statement?
  • Every class containing abstract method must be declared abstract.
  • Abstract class can directly be initiated with ‘new’ operator.
  • Abstract class can be initiated.
  • Abstract class does not contain any definition of implementation.

Question 7

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.
  • Overloads
  • Friendships
  • Inherits
  • Overrides

Question 8

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

  • 2

  • 3

  • 4

  • 5

Question 9

When one object reference variable is assigned to another object reference variable then
  • a copy of the object is created.
  • a copy of the reference is created.
  • a copy of the reference is not created.
  • it is illegal to assign one object reference variable to another object reference variable.

Question 10

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

There are 17 questions to complete.

Last Updated :
Take a part in the ongoing discussion