Deck 4: C++ Programming and Concepts: Inheritance, Data Types, Objects, and Output Prediction

Full screen (f)
exit full mode
Question
C++ was originally developed by ….......

A)donald knuth
B)bjarne sroustrups
C)dennis ritchie
D)none of these
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following approach is adopted in C++?

A)top down
B)bottom up
C)horizontal
D)vertical
Question
Which feature of C++ contain the concept of super class and subclass?

A)class and object
B)encapsulation
C)abstraction
D)inheritance
Question
The main intention of using inheritance is ….........

A)to help in converting one data type to other
B)to hide the details of base class
C)to extend the capabilities of base class
D)to help in modular programming
Question
If particular software can be used in some other application than the one for which it is created then it reveals ….........

A)data binding
B)data reusability
C)data encapsulation
D)none of these
Question
Which of the following data type does not return anything?

A)int
B)short
C)long
D)void
Question
How many objects can be created from an abstract class?

A)zero
B)one
C)two
D)as many as we want
Question
Which of the following statements is correct for a static member function?
1) It can access only other static members of its class.
2) It can be called using the class name, instead of objects

A)only 1 is correct
B)only 2 is correct
C)both 1 and 2 are correct
D)both 1 and 2 are incorrect
Question
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

A)compile-time error
B)preprocessing error
C)runtime error
D)runtime exception
Question
Which of the following interface determines how your program will be used by other program?

A)public
B)private
C)protected
D)none of these
Question
What is the difference between struct and class in C++?

A)all members of a structure are public and structures don't have constructors and destructors
B)members 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.
C)all members of a structure are public and structures don't have virtual functions
D)all above
Question
Predict the output of following C++ program#include<iostream> using namespace std;class Empty {}; int main(){cout <<sizeof(Empty); return 0;}

A)a non zero value
B)0
C)compile time error
D)runtime error
Question
class Test { int x;};int main(){Test t; cout <<t.x; return 0;}

A)0
B)garbage value
C)compile time error
Question
Which of the following is true?

A)all objects of a class share all data members of class
B)objects of a class do not share non-static members. every object has its own copy
C)objects of a class do not share codes of non-static methods, they have their own copy
D)none
Question
Which 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;}

A)compiler error: cannot have two objects with same class name
B)compiler error in line "::t.get();"
C)compiles and runs fine
Question
Which of the following is true about new when compared with malloc.
1) new is an operator, malloc is a function
2) new calls constructor, malloc doesn't
3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.

A)1 and 3
B)2 and 3
C)1 and 2
D)all 1,2,3
Question
Predict the output?#include <iostream> using namespace std;class Test{int x;Test() { x = 5;}};int main(){Test *t = new Test; cout <<t->x;}

A)compile time error
B)garbage
C)0
D)5
Question
What happens when delete is used for a NULL pointer? int *ptr = NULL; delete ptr;

A)compile time error
B)run time error
C)no effect
Question
Is it fine to call delete twice for a pointer?#include<iostream> using namespace std;int main(){int *ptr = new int; delete ptr;delete ptr; return 0;}
Question
Which of the followings is/are automatically added to every class, if we do not write our own.

A)copy constructor
B)assignment operator
C)a constructor without any parameter
D)all of the above
Question
Output of following program?#include<iostream> using namespace std; class Point {Point() { cout <<"Constructor called"; }};int main(){Point t1; return 0;}

A)compile time error
B)run time error
C)constructor called
Question
#include<iostream> using namespace std; class Point {public:Point() { cout <<"Constructor called"; }};int main(){Point t1, *t2; return 0;}

A)compiler error
B)constructor called constructor called
C)constructor called
Question
#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;}

A)compiler error
B)10 followed by garbage value
C)10 10
D)10 0
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/23
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: C++ Programming and Concepts: Inheritance, Data Types, Objects, and Output Prediction
1
C++ was originally developed by ….......

A)donald knuth
B)bjarne sroustrups
C)dennis ritchie
D)none of these
bjarne sroustrups
2
Which of the following approach is adopted in C++?

A)top down
B)bottom up
C)horizontal
D)vertical
bottom up
3
Which feature of C++ contain the concept of super class and subclass?

A)class and object
B)encapsulation
C)abstraction
D)inheritance
inheritance
4
The main intention of using inheritance is ….........

A)to help in converting one data type to other
B)to hide the details of base class
C)to extend the capabilities of base class
D)to help in modular programming
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
5
If particular software can be used in some other application than the one for which it is created then it reveals ….........

A)data binding
B)data reusability
C)data encapsulation
D)none of these
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following data type does not return anything?

A)int
B)short
C)long
D)void
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
7
How many objects can be created from an abstract class?

A)zero
B)one
C)two
D)as many as we want
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following statements is correct for a static member function?
1) It can access only other static members of its class.
2) It can be called using the class name, instead of objects

A)only 1 is correct
B)only 2 is correct
C)both 1 and 2 are correct
D)both 1 and 2 are incorrect
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
9
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

A)compile-time error
B)preprocessing error
C)runtime error
D)runtime exception
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following interface determines how your program will be used by other program?

A)public
B)private
C)protected
D)none of these
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
11
What is the difference between struct and class in C++?

A)all members of a structure are public and structures don't have constructors and destructors
B)members 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.
C)all members of a structure are public and structures don't have virtual functions
D)all above
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
12
Predict the output of following C++ program#include<iostream> using namespace std;class Empty {}; int main(){cout <<sizeof(Empty); return 0;}

A)a non zero value
B)0
C)compile time error
D)runtime error
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
13
class Test { int x;};int main(){Test t; cout <<t.x; return 0;}

A)0
B)garbage value
C)compile time error
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following is true?

A)all objects of a class share all data members of class
B)objects of a class do not share non-static members. every object has its own copy
C)objects of a class do not share codes of non-static methods, they have their own copy
D)none
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
15
Which 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;}

A)compiler error: cannot have two objects with same class name
B)compiler error in line "::t.get();"
C)compiles and runs fine
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following is true about new when compared with malloc.
1) new is an operator, malloc is a function
2) new calls constructor, malloc doesn't
3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.

A)1 and 3
B)2 and 3
C)1 and 2
D)all 1,2,3
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
17
Predict the output?#include <iostream> using namespace std;class Test{int x;Test() { x = 5;}};int main(){Test *t = new Test; cout <<t->x;}

A)compile time error
B)garbage
C)0
D)5
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
18
What happens when delete is used for a NULL pointer? int *ptr = NULL; delete ptr;

A)compile time error
B)run time error
C)no effect
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
19
Is it fine to call delete twice for a pointer?#include<iostream> using namespace std;int main(){int *ptr = new int; delete ptr;delete ptr; return 0;}
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the followings is/are automatically added to every class, if we do not write our own.

A)copy constructor
B)assignment operator
C)a constructor without any parameter
D)all of the above
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
21
Output of following program?#include<iostream> using namespace std; class Point {Point() { cout <<"Constructor called"; }};int main(){Point t1; return 0;}

A)compile time error
B)run time error
C)constructor called
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
22
#include<iostream> using namespace std; class Point {public:Point() { cout <<"Constructor called"; }};int main(){Point t1, *t2; return 0;}

A)compiler error
B)constructor called constructor called
C)constructor called
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
23
#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;}

A)compiler error
B)10 followed by garbage value
C)10 10
D)10 0
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 23 flashcards in this deck.