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

Test

C++ Virtual Functions

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 following is true about virtual functions in C++.
    1. AVirtual functions are functions that can be overridden in derived class with the same signature.
    2. BVirtual functions enable run-time polymorphism in a inheritance hierarchy.
    3. Cif a function is 'virtual' in the base class, the most-derived class's implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference. In non-virtual functions, the functions are called according to the type of reference or pointer.
    4. DAll of the above
  2. 2Predict output of the following program
    #include<iostream>
    using namespace std;

    class Base
    {
    public:
    virtual void show() { cout<<" In Base n"; }
    };

    class Derived: public Base
    {
    public:
    void show() { cout<<"In Derived n"; }
    };

    int main(void)
    {
    Base *bp = new Derived;
    bp->show();

    Base &br = *bp;
    br.show();

    return 0;
    }
    1. AIn Base
      In Base
    2. BIn Base
      In Derived
    3. CIn Derived
      In Derived
    4. DIn Derived
      In Base
  3. 3Output of following program
    #include<iostream>
    using namespace std;

    class Base
    {
    public:
    virtual void show() { cout<<" In Base n"; }
    };

    class Derived: public Base
    {
    public:
    void show() { cout<<"In Derived n"; }
    };

    int main(void)
    {
    Base *bp, b;
    Derived d;
    bp = &d;
    bp->show();
    bp = &b;
    bp->show();
    return 0;
    }
    1. AIn Base
      In Base
    2. BIn Base
      In Derived
    3. CIn Derived
      In Derived
    4. DIn Derived
      In Base
  4. 4Which of the following is true about pure virtual functions? 1) Their implementation is not provided in a class where they are declared. 2) If a class has a pure virtual function, then the class becomes abstract class and an instance of this class cannot be created.
    1. ABoth 1 and 2
    2. BOnly 1
    3. COnly 2
    4. DNeither 1 nor 2
  5. 5#include<iostream>
    using namespace std;

    class Base
    {
    public:
    virtual void show() = 0;
    };

    int main(void)
    {
    Base b;
    Base *bp;
    return 0;
    }
    1. AThere are compiler errors in lines "Base b;" and "Base bp;
    2. BThere is compiler error in line "Base b;"
    3. CThere is compiler error in line "Base bp;"
    4. DNo compiler Error
  6. 6Predict the output of following program.
    #include<iostream>
    using namespace std;
    class Base
    {
    public:
    virtual void show() = 0;
    };

    class Derived : public Base { };

    int main(void)
    {
    Derived q;
    return 0;
    }
    1. ACompiler Error: there cannot be an empty derived class
    2. BCompiler Error: Derived is abstract
    3. CNo compiler Error
  7. 7#include<iostream>
    using namespace std;

    class Base
    {
    public:
    virtual void show() = 0;
    };

    class Derived: public Base
    {
    public:
    void show() { cout<<"In Derived n"; }
    };

    int main(void)
    {
    Derived d;
    Base &br = d;
    br.show();
    return 0;
    }
    1. ACompiler Error in line "Base &br = d;"
    2. BEmpty Output
    3. CIn Derived
  8. 8#include <iostream>
    using namespace std;
    class Base {
    public:
    virtual Base() {}
    };
    int main() {
    return 0;
    }
    1. AYes
    2. BNo
  9. 9#include <iostream>
    using namespace std;
    class Base {
    public:
    virtual ~Base() {}
    };
    int main() {
    return 0;
    }
    1. AYES
    2. BNO
  10. 10#include<iostream>
    using namespace std;
    class Base {
    public:
    Base() { cout<<"Constructor: Base"<<endl; }
    virtual ~Base() { cout<<"Destructor : Base"<<endl; }
    };
    class Derived: public Base {
    public:
    Derived() { cout<<"Constructor: Derived"<<endl; }
    ~Derived() { cout<<"Destructor : Derived"<<endl; }
    };
    int main() {
    Base *Var = new Derived();
    delete Var;
    return 0;
    }
    1. AConstructor: Base
      Constructor: Derived
      Destructor : Derived
      Destructor : Base
    2. BConstructor: Base
      Constructor: Derived
      Destructor : Base
    3. CConstructor: Base
      Constructor: Derived
      Destructor : Derived
    4. DConstructor: Derived
      Destructor : Derived

Información

Descripción
C++ Test sobre C++ Virtual Functions, creado por PathaPadha Support el 04/11/2020.
Idioma
English
Visitas
199
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?