1. Question: Which of the following statements about constructors and destructors are true?

    A
    In a given class, constructors are always required to be defined, but destructors are not

    B
    Neither constructors nor destructors can take parameters

    C
    Constructors can take parameters, but destructors cannot

    D
    It is illegal to define a destructor as virtual

    E
    It is illegal to define a constructor as virtual

    F
    Both explicitly declared constructors and explicitly declared destructors are required in a class

    Note: Not available
    1. Report
  2. Question: Consider the sample code given below and answer the question that follows.
    class X {
      int   i;
    
    protected:
      float f;
    
    public:
      char  c;
    };
    
    class Y : private X { };
    Referring to the sample code above, which of the following data members of X are accessible from class Y

    A
    c

    B
    f

    C
    i

    D
    none

    Note: Not available
    1. Report
  3. Question: Consider the following code:
    class Animal
    {
    private:
        int weight;
    
    public:
        Animal()
        {
        }
    
        virtual void Speak()
        {
            cout << "Animal speaking";
        }
    };
    
    class Snake : public Animal
    {
    private:
        int length;
    
    public:
        Snake()
        {
        }
    
        void Speak()
        {
            cout << "Snake speakingrn";
        }
    };
    
    int main()
    {
        Animal *array = new Snake[10];
    
        for (int index= 0; index < 10; index++)
        {
            array->Speak();
            array++;
        }
        
        return 0;
    }
    What happens when the above code is compiled and executed?

    A
    The code will generate compilation errors

    B
    The code will compile and run fine. "Animal speaking" will be printed to the output

    C
    The code will compile and run fine. "Snake speaking" will be printed to the output

    D
    The code will crash at runtime

    Note: Not available
    1. Report
  4. Question: Consider the sample code given below and answer the question that follows.
    class A
    {
    public:
    A() {}
    ~A()
    {
    cout << "in destructor" << endl;
    }
    };
    void main()
    {
    A a;
    a.~A();
    }
    How many times will "in destructor" be output when the above code is compiled and executed?

    A
    0

    B
    1

    C
    2

    D
    A compile time error will be generated because destructors cannot be called directly

    Note: Not available
    1. Report
  5. Question: Consider the sample code given below and answer the question that follows.
    class Outer
    {
      public:
        class Inner
          {
            int Count;
            public:
            Inner(){};
          };
    };
    int main()
      {
    Inner innerObject;
    Outer outObject;
    return 0;
      }
    What will be the result when the above code is compiled?

    A
    The code will compile fine

    B
    There will be errors because classes cannot be defined inside other classes

    C
    There will be an error because Outer does not define a constructor

    D
    There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer

    E
    There will be no errors but a warning that Inner and Outer do not have destructors

    Note: Not available
    1. Report
  6. Question: Consider the sample code given below and answer the question that follows.
    1 class Car
    2 {
    3 private:
    4 int Wheels;
    5
    6 public:
    7 Car(int wheels = 0)
    8 : Wheels(wheels)
    9 {
    10 }
    11
    12 int GetWheels()
    13 {
    14 return Wheels;
    15 }
    16 };
    17 main()
    18 {
    19 Car c(4);
    20 cout << "No of wheels:" << c.GetWheels();
    21 }
    Which of the following lines from the sample code above are examples of data member definition?

    A
    4

    B
    7

    C
    8

    D
    14

    E
    19

    Note: Not available
    1. Report
  7. Question: Consider the following statements relating to static member functions and choose the appropriate options: 1. They have external linkage 2. They do not have 'this' pointers 3. They can be declared as virtual 4. They can have the same name as a non-static function that has the same argument types

    A
    All are true

    B
    Only 1, 2 and 4 are true

    C
    Only 1 and 2 are true

    D
    Only 1,3 and 4 are true

    E
    All are false

    Note: Not available
    1. Report
  8. Question: What access specifier allows only the class or a derived class to access a data member

    A
    private

    B
    protected

    C
    default

    D
    virtual

    E
    public

    Note: Not available
    1. Report
  9. Question: Consider the line of code given below and answer the question that follows.
    class screen;
    Which of the following statements are true about the class declaration above?

    A
    Incorrect syntax. The body of the class declaration is missing

    B
    Incorrect syntax. {}; is missing

    C
    The syntax is correct

    D
    Incorrect syntax. {} is missing

    E
    Incorrect syntax. Requires a *

    Note: Not available
    1. Report
  10. Question: What will be the output of the following code?
    class b
    {
        int i;
        public:
        virtual void vfoo()
      {
        cout <<"Base ";
      }
    };
    class d1 : public b
    {
        int j;
        public:
        void vfoo()
      {
        j++;
        cout <<"Derived";
      }
    };
    class d2 : public d1
    {
        int k;
    };
    void main()
    {
        b *p, ob;
        d2 ob2;
        p = &ob;
        p->vfoo();
        p = &ob2;
        p->vfoo();
    }

    A
    Base Base

    B
    Base Derived

    C
    Derived Base

    D
    Derived Derived

    Note: Not available
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd