¡GoConqr estrena diseño! Cuéntanos qué te parece.

Test

Constructors

PathaPadha Support 10 preguntas

Hacer el test

Este test tiene tiempo límite, así que se abre en el reproductor de siempre.

Preguntas del test (10)

  1. 1Which of the followings is/are automatically added to every class, if we do not write our own.
    1. ACopy Constructor
    2. BAssignment Operator
    3. CA constructor without any parameter
    4. DAll of the above
  2. 2When a copy constructor may be called?
    1. AWhen an object of the class is returned by value.
    2. BWhen an object of the class is passed (to a function) by value as an argument.
    3. CWhen an object is constructed based on another object of the same class
    4. DWhen compiler generates a temporary object.
    5. EAll of the above
  3. 3Output of following program?
    #include<iostream>
    using namespace std;
    class Point {
    Point() { cout << "Constructor called"; }
    };

    int main()
    {
    Point t1;
    return 0;
    }
    1. ACompiler Error
    2. BRuntime Error
    3. CConstructor called
  4. 4#include<iostream>
    using namespace std;
    class Point {
    public:
    Point() { cout << "Constructor called"; }
    };

    int main()
    {
    Point t1, *t2;
    return 0;
    }
    1. ACompiler Error
    2. BConstructor called
      Constructor called
    3. CConstructor called
  5. 5Output of following program?
    #include<iostream>
    using namespace std;

    class Point {
    public:
    Point() { cout << "Normal Constructor calledn"; }
    Point(const Point &t) { cout << "Copy constructor calledn"; }
    };

    int main()
    {
    Point *t1, *t2;
    t1 = new Point();
    t2 = new Point(*t1);
    Point t3 = *t1;
    Point t4;
    t4 = t3;
    return 0;
    }
    1. ANormal Constructor called
      Normal Constructor called

      Normal Constructor called

      Copy Constructor called

      Copy Constructor called

      Normal Constructor called

      Copy Constructor called
    2. BCopy Constructor called

      Normal Constructor called

      Copy Constructor called
      Normal Constructor called
      Copy Constructor called
    3. CNormal Constructor called
      Copy Constructor called

      Copy Constructor called

      Normal Constructor called
  6. 6#include<iostream>
    using namespace std;

    class X
    {
    public:
    int x;
    };

    int main()
    {
    X a = {10};
    X b = a;
    cout << a.x << " " << b.x;
    return 0;
    }
    1. A10 10
    2. B10 0
    3. C10 followed by Garbage Value
    4. DCompiler Error
  7. 7What is the output of following program?
    #include <iostream>
    using namespace std;

    class Point
    {
    int x, y;
    public:
    Point(const Point &p) { x = p.x; y = p.y; }
    int getX() { return x; }
    int getY() { return y; }
    };

    int main()
    {
    Point p1;
    Point p2 = p1;
    cout << "x = " << p2.getX() << " y = " << p2.getY();
    return 0;
    }
    1. ACompiler Error
    2. Bx = 0 y = 0
    3. Cx = garbage value y = garbage value
  8. 8#include <iostream>
    using namespace std;

    class Point
    {
    int x, y;
    public:
    Point(int i = 0, int j = 0) { x = i; y = j; }
    int getX() { return x; }
    int getY() { return y; }
    };

    int main()
    {
    Point p1;
    Point p2 = p1;
    cout << "x = " << p2.getX() << " y = " << p2.getY();
    return 0;
    }
    1. Ax = 0 y = 0
    2. BCompiler Error
    3. Cx = garbage value y = garbage value
  9. 9Predict the output of following program.
    #include<iostream>
    #include<stdlib.h>
    using namespace std;

    class Test
    {
    public:
    Test()
    { cout << "Constructor called"; }
    };

    int main()
    {
    Test *t = (Test *) malloc(sizeof(Test));
    return 0;
    }
    1. AConstructor called
    2. BEmpty
    3. CCompiler Error
    4. DRuntime error
  10. 10#include <iostream>
    using namespace std;

    class Test
    {
    public:
    Test() { cout << "Hello from Test() "; }
    } a;

    int main()
    {
    cout << "Main Started ";
    return 0;
    }
    1. AHello from Test() Main Started
    2. BCompiler Error: Global objects are not allowed
    3. CMain Started Hello from Test()
    4. DMain Started

Información

Descripción
C++ Test sobre Constructors, creado por PathaPadha Support el 27/10/2020.
Idioma
English
Visitas
60
Etiquetas
c++
Valoración
Aún sin valoraciones
Valora este test
Valora este test

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?