GoConqr has a new look! Let us know what you think.

Quiz

Class and Object

PathaPadha Support 17 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (17)

  1. 1What is the difference between struct and class in C++?
    1. AAll members of a structure are public and structures don't have constructors and destructors
    2. BMembers of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
    3. CAll members of a structure are public and structures don't have virtual functions
    4. Dall of the above
  2. 2Predict the output of following C++ program
    #include<iostream>
    using namespace std;

    class Empty {};

    int main()
    {
    cout << sizeof(Empty);
    return 0;
    }
    1. AA non-zero value
    2. B0
    3. Crun time error
    4. Dcompiler error
  3. 3class Test {
    int x;
    };
    int main()
    {
    Test t;
    cout << t.x;
    return 0;
    }
    1. A0
    2. Bgarbage value
    3. Ccompile error
  4. 4Which of the following is true?
    1. AAll objects of a class share all data members of class
    2. BObjects of a class do not share non-static members. Every object has its own copy.
    3. CObjects of a class do not share codes of non-static methods, they have their own copy
    4. Dnone of these
  5. 5Assume that an integer and a pointer each takes 4 bytes. Also, assume that there is no alignment in objects. Predict the output following program.
    #include<iostream>
    using namespace std;

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

    int main()
    {
    Test t;
    cout << sizeof(t) << " ";
    cout << sizeof(Test *);
    }
    1. A12 4
    2. B8 4
    3. C8 8
    4. D12 12
  6. 6Which of the following is true about the following program
    #include <iostream>
    class Test
    {
    public:
    int i;
    void get();
    };
    void Test::get()
    {
    std::cout << "Enter the value of i: ";
    std::cin >> i;
    }
    Test t; // Global object
    int main()
    {
    Test t; // local object
    t.get();
    std::cout << "value of i in local t: "<<t.i<<'n';
    ::t.get();
    std::cout << "value of i in global t: "<<::t.i<<'n';
    return 0;
    }
    1. ACompiler Error: Cannot have two objects with same class name
    2. BCompiler Error in Line "::t.get();"
    3. CCompiles and runs fine
  7. 7A member function can always access the data in __________ , (in C++)
    1. Athe class of which it is member
    2. Bthe object of which it is a member
    3. Cthe public part of its class
    4. Dthe private part of its class
  8. 8Which of the following is not correct for virtual function in C++ ?
    1. AMust be declared in public section of class.
    2. BVirtual function can be static.
    3. CVirtual function should be accessed using pointers.
    4. DVirtual function is defined in base class
  9. 9Which of the following is not correct (in C++) ?
    1.Class templates and function templates are instantiated in the same way
    2.Class templates differ from function templates in the way they are initiated
    3.Class template is initiated by defining an object using the template argument
    4.Class templates are generally used for storage classes
    1. A1
    2. B2,3
    3. C2,4
    4. D2,3,4
  10. 10Which of the following cannot be passed to a function in C++ ?
    1. Astructure
    2. Bconstant
    3. Carray
    4. Dheader file

Information

Description
C++ Quiz on Class and Object, created by PathaPadha Support on 28/10/2020.
Language
English
Views
17
Tags
c++
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?