Quiz
Class and Object
This quiz has a time limit, so it opens in the usual player.
Questions in this quiz (17)
1What is the difference between struct and class in C++?
- AAll members of a structure are public and structures don't have constructors and destructors
- 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.
- CAll members of a structure are public and structures don't have virtual functions
- Dall of the above
2Predict the output of following C++ program
#include<iostream>
using namespace std;
class Empty {};
int main()
{
cout << sizeof(Empty);
return 0;
}- AA non-zero value
- B0
- Crun time error
- Dcompiler error
3class Test {
int x;
};
int main()
{
Test t;
cout << t.x;
return 0;
}- A0
- Bgarbage value
- Ccompile error
4Which of the following is true?
- AAll objects of a class share all data members of class
- BObjects of a class do not share non-static members. Every object has its own copy.
- CObjects of a class do not share codes of non-static methods, they have their own copy
- Dnone of these
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 *);
}- A12 4
- B8 4
- C8 8
- D12 12
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;
}- ACompiler Error: Cannot have two objects with same class name
- BCompiler Error in Line "::t.get();"
- CCompiles and runs fine
7A member function can always access the data in __________ , (in C++)
- Athe class of which it is member
- Bthe object of which it is a member
- Cthe public part of its class
- Dthe private part of its class
8Which of the following is not correct for virtual function in C++ ?
- AMust be declared in public section of class.
- BVirtual function can be static.
- CVirtual function should be accessed using pointers.
- DVirtual function is defined in base class
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- A1
- B2,3
- C2,4
- D2,3,4
10Which of the following cannot be passed to a function in C++ ?
- Astructure
- Bconstant
- Carray
- Dheader file
11Which of the following is a correct statement?
- AComposition is a strong type of association between two classes with full ownership
- BComposition is a strong type of association between two classes with partial ownership.
- CComposition is a weak type of association between two classes with partial ownership.
- DComposition is a weak type of association between two classes with strong ownership.
12Which of the following is not a correct statement?
- AEvery class containing abstract method must be declared abstract
- BAbstract class can directly be initiated with ‘new’ operator
- CAbstract class can be initiated
- DAbstract class does not contain any definition of implementation
13When 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.
- AOverloads
- Bfriendships
- Cinherits
- Doverrides
14It is possible to define a class within a class termed as nested class. There are _____ types of nested classes
- A3
- B4
- C5
- D2
15When one object reference variable is assigned to another object reference variable then
- Aa copy of the object is created.
- Ba copy of the reference is created
- Ca copy of the reference is not created
- Dit is illegal to assign one object reference variable to another object reference variable.
16Which of the following, in C++, is inherited in a derived class from base class ?
- Aconstructor
- Bdestructor
- Cdata members
- Dall of the above
17Which of the following is not a member of class?
- Astatic function
- Bfriend function
- Cconst function
- Dvirtual finction
Information
- Description
- C++ Quiz on Class and Object, created by PathaPadha Support on 28/10/2020.
- Author
- PathaPadha Support
- Language
- English
- Views
- 17
- Tags
- Rating
- No ratings yet Rate this quiz