22316 Object Oriented Programming Using C++ MCQs PDF Download

22316 Object Oriented Programming Using C++ MCQs PDF Download
Welcome Diploma and degree students to mypractically. Get Object Oriented Programming Using C++ MCQs For Electrical Engineering Students PDF.

This important and major post is helpful and beneficial for MSBTE Computer/IT Engineering Diploma and Degree Students.

In this article you will get MSBTE Computer Engineering 22316 Object Oriented Programming Using C++ MCQs Pdf.

By getting this OOP mcqs Object Oriented Programming Using C++ Mcqs, you will easily get more marks for MSBTE Exams.

In this post we have added MSBTE unit wise and chapter wise Object Oriented Programming Using C++ MCQs for Computer Engineering MCQs Pdf, so if you like it make sure you will share with your MSBTE diploma & degree Students


Question Bank for Multiple Choice Questions

Program: Diploma in Computer engineering Program Code:- CO
Scheme:-I Semester:- 3
Course:- Object Oriented Programming Course Code:- 22316

{tocify} $title={Table of Contents}

01 – Principles of Object Oriented Programming

Marks:-14 Content of Chapter:-
1. Which was the first purely object-oriented programming language developed?
a) Java
b) C++
c) SmallTalk
d) Kotlin

Answer: c
Explanation: SmallTalk was the first programming language developed which was purely object oriented. It was developed by Alan Kay. OOP concept came into the picture in 1970‟s.

2. Which of the following best defines a class?
a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object

Answer: c
Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that are provided by an object of a specific class. It can‟t be called as parent or instance of an object. Class in general describes all the properties of an object.
 

3. Who invented OOP?
a) Alan Kay
b) Andrea Ferro
c) Dennis Ritchie
d) Adele Goldberg

Answer: a
Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got rewarded for OOP.

4. What is the additional feature in classes that was not in structures?
a) Data members
b) Member functions
c) Static data allowed
d) Public access specifier

Answer: b
Explanation: Member functions are allowed inside a class but were not present in structure concept. Data members, static data and public access specifiers were present in structures too.

5. Which is not feature of OOP in general definitions?
a) Code reusability
b) Modularity
c) Duplicate/Redundant data
d) Efficient Code

Answer: c
Explanation: Duplicate/Redundant data is dependent on programmer and hence can‟t be guaranteed by OOP. Code reusability is done using inheritance. Modularity is supported by using different code files and classes. Codes are more efficient because of features of OOP.

$ads={1}


6. Pure OOP can be implemented without using class in a program. (True or False)
a) True
b) False

Answer: b
Explanation: It‟s false because for a program to be pure OO, everything must be written inside classes. Ifthis rule is violated, the program can‟t be labelled as purely OO.

7. Which Feature of OOP illustrated the code reusability?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance

Answer: d
Explanation: Using inheritance we can reuse the code already written and also can avoid creation of many new functions or variables, as that can be done one time and be reused, using classes.
 

8. Which language does not support all 4 types of inheritance?
a) C++
b) Java
c) Kotlin
d) Small Talk
Answer: b
Explanation: Java doesn‟t support all 4 types of inheritance. It doesn‟t support multiple inheritance. But the multiple inheritance can be implemented using interfaces in Java.

9. How many classes can be defined in a single program?
a) Only 1
b) Only 100
c) Only 999
d) As many as you want
Answer: d
Explanation: Any number of classes can be defined inside a program, provided that their names are
different. In java, if public class is present then it must have the same name as that of file.

10. When did the OOP concept first come into picture?
a) 1970’s
b) 1980‟s
c) 1993
d) 1995
Answer: a
Explanation: OOP first came into picture in 1970‟s by Alan and his team. Later it was used by some programming languages and got implemented successfully, SmallTalk was first language to use pure OOP and followed all rules strictly.

11. Which concept of OOP is false for C++?
a) Code can be written without using classes
b) Code must contain at least one class
c) A class must have member functions
d) At least one object should be declared in code
Answer: b
Explanation: In C++, it‟s not necessary to use classes, and hence codes can be written without using OOP concept. Classes may or may not contain member functions, so it‟s not a necessary condition in C++. And, an object can only be declared in a code if its class is defined/included via header file.

12. Which header file is required in C++ to use OOP?
a) iostream.h
b) stdio.h
c) stdlib.h
d) OOP can be used without using any header file
Answer: d
Explanation: We need not include any specific header file to use OOP concept in C++, only specific functions used in code need their respective header files to be included or classes should be defined if needed.
 

13. Which of the two features match each other?
a) Inheritance and Encapsulation
b) Encapsulation and Polymorphism
c) Encapsulation and  Abstraction
d) Abstraction and Polymorphism
Answer: c
Explanation: Encapsulation and Abstraction are similar features. Encapsulation is actually binding all the properties in a single class or we can say hiding all the features of object inside a class. And Abstraction is hiding unwanted data (for user) and showing only the data required by the user of program.

14. Which of the following cannot be friend?
a) Function
b) Class
c) Object
d) Operator function

15. Which of the following concepts of OOPS means exposing only necessary information to client?
a) Encapsulation
b) Abstraction
c) Data hiding
d) Data binding

16. cout is a/an .
a) operator
b) function
c) object
d) macro

17. Which of the following is an abstract data type?
a) int
b) double
c) string
d) Class

18. Which of the following approach is adapted by C++?
a) Top-down
b) Bottom-up
c) Right-left
d) Left-right

19. Which of the following concepts means wrapping up of data and functions together?
a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism

20. Which of the following operator is overloaded for object cout?
a) >>
b) <<
c)  +
d)  =
 

21 .Which of the following is the correct class of the object cout?
a) iostream
b) istream
c) ostream
d) ifstream

22. Which of the following statement is correct?
a) C++ allows static type checking.
b) C++ allows dynamic type checking.
c) C++ allows static member function be of type const.
d) Both A and B.

23. What's wrong? for (int k = 2, k <=12, k++)
a. the increment should always be ++k
b. the variable must always be the letter i when using a for loop
c. there should be a semicolon at the end of the statement
d. the commas should be semicolons

24What does STL stand for?
a) Simple Template Library
b) Standard Template Library
c) Static Type Library
d) Single Type-based Library

25. Each pass through a loop is called a/an
a) enumeration
b) iteration
c) culmination
d) pass through

26. If a member needs to have unique value for all the objects of that same class, d eclare the member as
a) Global variable outside class
b) Local variable inside constructor
c) Static variable inside class
d) Dynamic variable inside class

27. Which looping process checks the test condition at the end of the loop?
a. for
b. while
c. do-while
d. no looping process checks the test condition at the


02. Classes and Objects

Marks:-18

1. Which of the following is not type of class?
a) Abstract Class
b) Final Class
c) Start Class
d) String Class
Answer: c
Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper, anonymous, input-output, string, system, network. We may further divide the classes into parent class and subclass if inheritance is used.

2. Class is pass by
a) Value
b) Reference
c) Value or Reference, depending on program
d) Copy
Answer: b
Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn‟t depend on the program.

3. What is default access specifier for data members or member functions declared within a class without any specifier, in C++?
a) Private
b) Protcted
c) Public
d) Depends on compiler
Answer: a
Explanation: The data members and member functions are Private by default in C++ classes, if none of the accessspecifier is used. It is actually made to increase the privacy of data.

4. Which is most appropriate comment on following class definition? class Student
{
int a;
public : float a;
}
a) Error : same variable name can’t be used twice
b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct
[
Answer: a
Explanation: Same variable can‟t be defined twice in same scope. Even if the data types are different, variable name must be different. There is no rule like Public member should come first or last.
 
5. Which is known as a generic class?
a) Abstract class
b) Final class
c) Template class
d) Efficient Code

Answer: c
Explanation: Template classes are known to be generic classes because those can be used for any data type value and the same class can be used for all the variables of different data types.

6. Size of a class is
a) Sum of the size of all the variables declared inside the class
b) Sum of the size of all the variables along with inherited variables in the class
c) Size of the largest size of variable
d) Classes doesn’t have any size

Answer: d
Explanation: Classes doesn‟t have any size, actually the size of object of the class can be defined. That is done only when an object is created and its constructor is called.

7. Which of the following describes a friend class?
a) Friend class can access all the private members of the class, of which it is afriend
b) Friend class can only access protected members of the class, of which it is afriend
c) Friend class don‟t have any implementation
d) Friend class can‟t access any data member of another class but can use it‟s methods

Answer: a
Explanation: A friend class can access all the private members of another class, of which it is a friend. It is a special class provided to use when
you need to reuse the data of a class but don‟t want that class to have those special functions.

8. What is the scope of a class nested inside another class?
a) Protected scope
b) Private scope
c) Global scope
d) Depends on access specifier and inheritance used

Answer: d
Explanation: It depends on the access specifier and the type of inheritance used with the class, because if the class is inherited then the nested class can be used by subclass too, provided it‟s not of private type.

9. Class with main() function can be inherited.
a) True
b) False

Answer: a
Explanation: The class containing main function can be inherited and hence the program can be executed using the derived class names also in java.
 
10. Which among the following is false, for a member function of a class?
a) All member functions must be defined
b) Member functions can be defined inside or outside the classbody
c) Member functions need not be declared inside the classdefinition
d) Member functions can be made friend to another class using the friend keyword Answer: c
Explanation: Member functions must be declared inside class body, though the definition can be given outside theclass body. There is no way to declare the member functions outside the class.

11. Which syntax for class definition is wrong?
a) class student{ };
b) student class{ };
c) class student{ public: student(int a){ } };
d) class student{ student(int a){} };
Answer: b
Explanation: Keyword class should come first. Class name should come after keyword class. Parameterized constructor definition depends on programmer so it can be left empty also.

12. Which of the following pairs are similar?
a) Class and object
b) Class and structure
c) Structure and object
d) Structure and functions
Answer: b
Explanation: Class and structure are similar to each other. Only major difference is that a structure doesn‟t have member functions whereas the class can have both data members and member functions.

13. Which among the following is false for class features?
a) Classes may/may not have both data members and member functions
b) Class definition must be ended with a colon
c) Class can have only member functions with no data members
d) Class is similar to union and structures

Answer: b
Explanation: Class definition must end with a semicolon, not colon. Class can have only member functions in its body with no data members.

14. Instance of which type of class can‟t be created?
a) Anonymous class
b) Nested class
c) Parent class
d) Abstract class
Answer: d
Explanation: Instance of abstract class can‟t be created as it will not have any constructor of its own, hence while creating an instance of class, it can‟t initialize the object members. Actually the class inheriting the abstract class can have its instance because it will have implementation of all members.
15. Which definition best describes an object?
a) Instance of a class
b) Instance of itself
c) Child of a class
d) Overview of a class Answer: a
Explanation: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.
 

16. How many objects can be declared of a specific class in a single program? a) 32768 b) 127
c) 1
d) As many as you want

Answer: d
Explanation: You can create as many objects of a specific class as you want, provided enough memory is available.

17. Which among the following is false?
a) Object must be created before using members of a class
b) Memory for an object is allocated only after its constructor is called
c) Objects can’t be passed by reference
d) Objects size depends on its class data members

Answer: c
Explanation: Objects can be passed by reference. Objects can be passed by value also. If the object of a class is not created, we can‟t use members of thatclass.

18. Which of the following is incorrect?
a) class student{ }s;
b) class student{ }; student s;
c) class student{ }s[];
d) class student{ }; student s[5];

Answer: c
Explanation: The array must be specified with a size. You can‟t declare object array, or any other linear array without specifying its size. It‟s a mandatory field.

19. The object can‟t be
a) Passed by reference
b) Passed by value
c) Passed by copy
d) Passed as function

Answer: d
Explanation: Object can‟t be passed as function as it is an instance of some class, it‟s not a function. Object can bepassed by reference, value or copy. There is no term defined as pass as function for objects.

20. What is size of the object of following class (64 bit system)?
class student int char name[20]; static int

a) 20
b) 22
c) 24
d) 28
Answer: c
Explanation: The size of any object of student class will be of size 4+20=24, because static members are not reallyconsidered as property of a single object. So static variables size will not be added.
 

21. Functions can‟t return objects.
a) True
b) False

Answer: b
Explanation: Functions can always return an object if the return type is same as that of object being returned. Carehas to be taken while writing the prototype of the function.

22. How members of an object are accessed?
a) Using dot operator/period symbol
b) Using scope resolution operator
c) Using member names directly
d) Using pointer only

Answer: a
Explanation: Using dot operator after the name of object we can access its members. It is not necessary to use thepointers. We can‟t use the names directly because it may be used outside the class.

23. If a local class is defined in a function, which of the following is true for an object of that class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in thatfunction

Answer: d
Explanation: For an object which belongs to a local class, it is mandatory to declare and use the object within the function because the class is accessible locally within the class only.

24. Which among the  following is wrong?
a) class student{ }; student s;
b) abstract class student{ }; student s;
c) abstract class student{ }s[50000000];
d) abstract class student{ }; class toppers: public student{ }; toppert;

Answer: b
Explanation: We can never create instance of an abstract class. Abstract classes doesn‟t have constructors and hence when an instance is created there is no facility to initialize its members. Option d is correct because topper class is inheriting the base abstract class student, and hence topper class object can be created easily.

25. Object declared in main() function
a) Can be used by any other function
b) Can be used by main() function of any other program
c) Can’t be used by any other function
d) Can be accessed using scope resolution operator

Answer: c
Explanation: The object declared in main() have local scope inside main() function only. It can‟t be used outside main() function. Scope resolution operator is used to access globally declared variables/objects.
 

26. When an object is returned
a) A temporary object is created to return the value
b) The same object used in function is used to return the value
c) The Object can be returned without creation of temporary object
d) Object are returned implicitly, we can‟t say how it happens insideprogram

Answer: a
Explanation: A temporary object is created to return the value. It is created because the object used in function isdestroyed as soon as the function is returned. The temporary variable returns the value and then gets destroyed.

27. Which among the following is correct?
a) class student{ }s1,s2; s1.student()=s2.student();
b) class student{ }s1; class topper{ }t1; s1=t1;
c) class student{ }s1,s2; s1=s2;
d) class student{ }s1; class topper{ }t1;s1.student()=s2.topper();

Answer: c
Explanation: Only if the objects are of same class then their data can be copied from to another using assignment operator. This actually comes under operator overloading. Class constructors can‟t be assigned any explicit value as in option class student{ }s1; class topper{ }t1; s1=t1; and class student{ }s1; class topper{ }t1; s1.student()=s2.topper();.
28. Which among following is correct for initializing the class below?class student{ int marks; int cgpa;
public: student(int i, intj)
{
marks=I; cgpa=j

}
};
a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };
b) student s[2]={ s(394,9), s(222,5) };
c) student s[2]={ s1(392,9), s2(222,5)  };
d) student s[2]={ s[392,9], s2[222,5] };

Answer: b
Explanation: It is the way we can initialize the data members for an object array using parameterized constructor. We can do this to pass our own intended values to initialize the object array data.

29. Object can‟t be used with pointers because they belong to user defined class, and compiler can‟t decide the type of data may be used inside the class.
a) True
b) False
Answer: b
Explanation: The explanation given is wrong because object can always be used with pointers like with any other variables. Compiler
doesn‟t have to know the structure of the class to use a pointer because the pointers only points to a memory address/stores that address.
 

03 – Extending classes using Inheritance

Marks:-16 Content of Chapter:-
Introduction, defining a derived class, visibility modes & effects.
Types of Inheritance : Single inheritance, multilevel inheritance, hierarchical inheritance, hybrid inheritance
Virtual base class, abstract class, constructors in derived class.

1. If class B inherits class A privately. And class B has a friend function. Will the friend function be able to access the private member of class A?
a) Yes, because friend function can access all the members
b) Yes, because friend function is of class B
c) No, because friend function can only access private members of friend class
d) No, because friend function can access private member of class A also

2. When the inheritance is private, the private methods in base class are in the derived class (in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public

3 .Which design patterns benefit from the multiple inheritances?
A. Adapter and observer pattern
B. Code pattern
C. Glue pattern
D. None of the mentioned

4 What is meant by multiple inheritance?
A. Deriving a base class from derived class
B. Deriving a derived class from base class
C. Deriving a derived class from more than one base class
D. None of the mentioned
5. What will be the order of execution of base class constructors in the following method of inheritance.class a: public b, public c {...};
A. b(); c(); a();
B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();

6. Inheritance allow in C++ Program?
A. Class Re-usability
B. Creating a hierarchy of classes
C. Extendibility
D. All of the above

7. Can we pass parameters to base class constructor though derived class or derived class constructor?
A. Yes
B. No
C. May Be
D. Can't Say

8 What are the things are inherited from the base class?
 
A. Constructor and its destructor
B. Operator=() members
C. Friends
D. All of the above

9. Which of the following advantages we lose by using multiple inheritance?
A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned

10. Which symbol is used to create multiple inheritance?
A. Dot
B. Comma
C. Dollar
D. None of the above

12. There are different types of inheritance
a) Single level
b) multiple
c) multilevel
d) All

13. Which class can have member functions without their implementation?
a) Default class
b) String class
c) Template  class
d) Abstract class

Answer: d
Explanation: Abstract classes can have member functions with no implementation, where the inheriting subclassesmust implement those functions.

14. Which of the following concepts provides facility of using object of one class inside another class?
a) Encapsulation
b) Abstraction
c) Composition
d) Inheritance
 

15 . y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?
a. y.operator+=( z )
b. y = y + z
c. y = y operator+= z
d. y operator+=( y + z ) 
Answer: B

16 . For operators overloaded as non-static member functions:
a. Both binary and unary operators take one argument.
b. Neither binary nor unary operators can have arguments.
c. Binary operators can have two arguments and unary operators can have one.
d. Binary operators can have one argument, and unary operators cannot have any. 
Answer: A

17. Which of the following is false?
a. Two arrays cannot be meaningfully compared with equality or relationaloperators.
b. C++ ensures that you cannot “walk off” either end of an array.
c. An entire non-char array cannot be input or output at once.
d. Arrays cannot be assigned to one another (i.e., array1 = array2;). 
Answer: C

13. The array subscript operator [], when overloaded, cannot:
a. Take multiple values inside (e.g., [4 8]).
b. Take a float as an operand.
c. Take user-defined objects as operands.
d. Be used with linked list classes.
[


Answer: C
14. A copy constructor:
a. is a constructor that takes no arguments.
b. is a constructor with only default arguments.
c. is a constructor that initializes a newly declared object to the value of an existing object of the same class.
d. None of the above.
Answer:C


15. Copy constructors must receive its argument by reference because:
a. the pointer needs to know the address of the original data, not a temporary copyof it.
b. the copy of the argument passed by value has function scope.
c. otherwise the constructor will only make a copy of a pointer to an object.
d. otherwise infinite recursion occurs. 
Answer:B

16. To prevent class objects from being copied:
a. Make the copy constructor private.
b. Make the overloaded assignment operator private.
c. Both (a) and (b).
d. None of the above. 
Answer :C

17. Conversion constructors:
a. Can convert between user-defined types.
b. Are implicitly defined by the compiler if not explicitly written by theprogrammer.
c. Cannot convert built-in types to user defined types.
d. Can have multiple arguments.
Answer:A

18. The prototypes of overloaded cast operator functions do not:
a. Specify the type they convert to.
b. Need to be defined inside the class whose objects are being converted.
c. Specify the type that is being converted.
d. Specify a return type. 
Answer: A

19. Which of the following lines would be the prototype for an overloaded cast operatorfunction that
converts an object of user-defined type Time into a double?
a. Time::operator_cast(double) const
b. Time::static_cast double() const;
c. Time::operator double() const;
d. d. Time::double() const;
Answer:A
 

21. Can we pass parameters to base class constructor though derived class or derived class constructor?
a.Yes b.No
Answer:A

24Can we pass parameters to base class constructor though derived class or derived class constructor?
a. constructor of derived class will be invoked first
b. constructor of base class will be invoked first
c. constructor of derived class will be executed first followed by base class
d. constructor of base class will be executed first followed by derived class
Answer:D

25. In Multipath inheritance, in order to remove duplicate set of records in child class, we .
a. Write Virtual function in parent classes
b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these
Answer:C
 
26. When a child class inherits traits from more than one parent class, this type of inheritance is called inheritance.
a. Hierarchical
b. Hybrid
c. Multilevel
d. Multiple 
Answer:D

27. What is the difference between protected and private access specifiers in inheritance?
a. private member  is not inheritable and not accessible in  derived  class.
b. protected member is inheritable and also accessible in derived class.
c. Both are inheritable but private is accessible in the derived class.
d. Both are inheritable but protected is not accessible in the derived class. 
Answer:B

28. When a base class is privately inherited by the derived class, then .
a. protected members of the base class become private members of derived class
b. public members of the base class become private members of derived class
c. both a and b
d. only b 
Answer: C


30. When base class is derived in protected mode, then .
1. public members of base class become private members of derived class.
2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.
a. Only 1, 5
b. Only 1, 6
c. Only 2, 6
d. Only 2, 4 
Answer:D

31. class X, class Y and class Z are derived from class BASE. This is inheritance.
a. Multiple
b. Multilevel
c. Hierarchical
d. Single
Answer:C

32. Reusability of the code can be achieved in CPP through .
a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c 
Answer:C

33. Which programming language doesn‟t support multiple inheritance?
a) C++ and Java
b) C and C++
c) Java and SmallTalk
d) Java
Answer:D
 
34. Which access type data gets derived as private member in derived class?
a) Private
b) Public
c) Protected
d) Protected and Private 
Answer:A

35. If a derived class object is created, which constructor is called first?
a) Base class constructor
b) Derived class constructor
c) Depends on how we call the object
d) Not possible Answer:A

04 – Pointers & Polymorphism in C++

Marks:-14
 
Content of Chapter:-
Concepts of Pointer: Pointer declaration Pointer operator, address operator, Pointer arithmetic
Pointer to Object: Pointer to Object, this pointer , Pointer to derived class
Introduction, Types of polymorphism .
Compile time Polymorphism: Function overloading operator overloading: Overloading unary and binaryoperatorsRules for operator overloading.
Run time polymorphism: Virtual functions, rules for virtual functions, pure virtual function.

1. Which of the following is the correct way to declare a pointer ?
A. int *ptr
B. int ptr
C. int &ptr
D. All of the above Answer:A

2. Which of the following gives the [value] stored at the address pointed to by the pointer : ptr?
A. Value(ptr)
B. ptr
C. &ptr
D. *ptr 
Answer:D

3. A pointer can be initialized with
A. Null
B. Zero
C. Address of an object of same type
D. All of the above 
Answer:D
 
4. Choose the right option string* x, y;
A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. Both x and y are pointers to string types
D. none of the above 
Answer:A

5. Generic pointers can be declared with .
A. auto
B. void
C. asm
D. None of the above 
Answer:B

6. Which from the following is not a correct way to pass a pointer to a function?
A. Non-constant pointer to non-constant data
B. A non-constant pointer to constant data
C. A constant pointer to non-constant data
D. All of the above 
Answer: D

7. Referencing a value through a pointer is called
A. Direct calling
B. Indirection
C. Pointer referencing
D. All of the above 
Answer:B

8. Choose the right option. string* x, y;
a) x is a pointer to a string, y is a string
b) y is a pointer to a string, x is a string
c) both x and y are pointers to string types
d) y is a pointer to a string 
Answer:A
 
9. Which one of the following is not a possible state for a pointer.
a) hold the address of the specific object
b) point one past the end of an object
c) zero
d) point to a type 
Answer:D

10. Which of the following is illegal?
a) int *ip;
b) string s, *sp = 0;
c) int i; double* dp = &i;
d) int *pi = 0; 
Answer:C

11. What will happen in the following C++ code snippet?int a
=100, b =200;
int *p = &a, *q = &b ;p = q
a) b is assigned to a
b) p now points to b
c) a is assigned to b
d) q now points to a 
Answer:B


13. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char andreturns a pointer to a pointer to a integer is
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int **fun(float*, char**)
d) int ***fun(*float, **char) 
Answer:C
Explanation: Function that takes pointer to a float, a pointer to a pointer to a char and returns apointer to a pointer to a integer is int **fun(float*, char**).

14. What is size of generic pointer in C++ (in 32-bit platform)?
a) 2
b) 4
c) 8
d) 0
Answer: B
Explanation: Size of any type of pointer is 4 bytes in 32-bit platforms.

15. What will be the output of the following C++ code?#include
<iostream>
using namespace std;int main() {
int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
cout << *(a[1] + 2) << * (*(a + 1) + 2) << [1[a]];

return 0;
}
a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error 
Answer: B

Explanation: a[1][2] means 1 * (4)+2 = 6th element of an array starting from zero.

16. What will be the output of the following C++ code?#include
<iostream>
using namespace std;int main() {
int i;
const char *arr[] = {"c", "c++", "java", "VBA"};const char
*(*ptr)[4] = &arr; cout << ++(*ptr)[2];

return 0;
}
a) ava
b) java
c) c++
d) compile time error Answer: A
Explanation: In this program we are moving the pointer from first position to second position and printing the remaining value.

17. The void pointer can point to which type of objects?
a) int
b) float
c) double
d) all of the mentioned Answer: D
Explanation: Because it doesn‟t know the type of object it is pointing to, So it can point to all objects.

18. When does the void pointer can be dereferenced?
a) when it doesn‟t point to any value
b) when it cast to another type of object
c) using delete keyword
d) using shift keyword Answer: B
Explanation: By casting the pointer to another data type, it can be dereferenced from the void pointer.
 
19. A non-member function that is given access to all members of a class within it is declared, is called
a. Access function
b. Friend function
c. Operator functions
d. None of them Answer:B
20. There are how many different ways to pass a pointer to a function?
a. 1 b.2 c.3 d.4
Answer:D
21. A void pointer cannot point to which of these?
A. Methods in c++
B. Class member in c++
C. Both A & B
D. None of the above
Answer : B

Explanation: Because the class member will have a definite type, So it cannot pointed by avoid pointer.
22. The correct statement for a function that takes pointer to a float, a pointer to a pointer toa char and returns a pointer to a pointer to a integer is
A. int **fun(float**, char**)
B. int *fun(float*, char*)
C. int ***fun(float*, char**)
D. int ***fun(*float, **char) Answer: C
Explanation: The correct statement for a function that takes pointer to a float, a pointer to apointer to a char and returns a pointer to a pointer to a integer is int ***fun(float*, char**).
23. Which of the following is illegal?
A. int *ip;
B. string s, *sp = 0;
C. int i; double* dp = &i
D. int *pi = 0; Answer : C
Explanation: dp is initialized int value of i.

24. Which one of the following is not a possible state for a pointer?
A. Hold the address of the specific object
B. Point one past the end of an object
C. Zero
D. Point to a type Answer: D

Explanation: A pointer can be in only 3 states a,b and c.
25.A pointer contains .
A. Address of a variable
B. Name of the variable
C. Value of the variable
D. None of the above Answer: A

26. Assigning reference to an object a.Will create another copy of the object
b. Will create two different copies of the object
c. Will not create any other copy of the object
d. Will not refer to the object
Answer: C

27. Which is correct syntax for declaring pointer to object? a.className* objectName;
b.className objectName; c.*className objectName; d.className objectName(); Answer: A
28. Which operator should be used to access the members of the class using object pointer?a.Dot operator b.Colon to the member c.Scope
resolution operatord.Arrow operator
Answer:D
 
29. How does compiler decide the intended object to be used, if more than one object are used?

a.Using object name b.Using an integer pointer c.Using this pointer d.Using void pointer
Answer:C

30. If pointer to an object is declared, a.It can store any type of address
b. It can store only void addresses
c. It can only store address of integer type
d. It can only store object address of class type specified Answer:D

31. Polymorphism is achieved through
a. Heritance
b. Poly programming
c. Encapsulation
d. Overloading Answer:D


32. The mechanism of giving special meaning to an operator is called
(A) Object
(B) Inheritance
(C) Function overloading
(D) Operator Overloading Answer:D


33. In function overloading do not use the function name for two unrelated functions.
(A) Same
(B) Different
(C) Similar
(D) Complement Answer: A
 
34. The operator must have at least one operand of user defined type.
(A) New
(B) Overloaded
(C) Existing
(D) Binary Answer: B
35. Which of the following operators cannot be overloaded?
(A) +
(B) ++
(C) --
(D) ::
Answer: D

36. Which one is the best description of polymorphism?
A. It is the ability for undefined message/data to be processed in at least one way
B. It is the ability for a message/data to be processed in more than one form
C. It is the ability for many messages/data to be processed in many ways
D. none of these Answer: B

37. The languages that support classes but not polymorphism is called?
A. child Class-based language
B. Class-based language
C. Object-based language
D. Procedure Oriented language Answer: C

38. Which type of function shows polymorphism among the following?
A. Inline function
B. Virtual function
C. Undefined functions
D. Class member functions Answer: B

39. Which one of the following can show polymorphism?
A. Overloading ||
B. Overloading &&
C. Overloading <<
D. Overloading +=
Answer: C

40. The problem may arise if we use abstract class functions for polymorphism in OOP?
A. All classes are converted as an abstract class
B. All the derived classes must implement the undefined functions
C. abstract class must have derived a class
D. Derived classes can‟t redefine the function
Answer:C

41. If two classes derive one base class and redefine a function of the base class, also overloadsome operators inside the body of the class. Among these two things of function and operator overloading, the polymorphism is used where?
A. Function overloading only
B. Operator overloading only
C. Either function overloading or operator overloading because polymorphism can be applied onlyonce in a program
D. Both of these are using polymorphism 
Answer:C

42. Run time polymorphism is achieved only when a Is accessed through a pointer to
the base class.
A) static function
B) Real function
C. Member function


43. A class serves as base class for many derived classes it is called:
A. polymorphism
B. multipath inheritance C .hierarchical inheritance
C. none of these Answer: C


44. Compile time polymorphism in C++ language area.Operator overloading
b.Function overloading c.Function overriding
d.B Only
e.A & B Answer: E
 


45. C++ abstract class can contain
46. a.Pure virtual function b.Non-virtual function c.Only pure virtual function
d.Both pure virtual and non-virtual function Answer: D

47. Which of the following cannot be overloaded in C++? a.Increment operator
b.Constructor c.Destructor
d.New and delete operator Answer: C

48. Which is the correct declaration of pure virtual function in C++a.virtual void func = 0;
b.virtual void func() = 0; c.virtual void func(){0};
d.void func() = 0; Answer: B

49. In a class, pure virtual functions in C++ is useda.To create an interface
b.To make a class abstract
c.To force derived class to implement the pure virtual functiond.All the above
Answer: D

50. Run time polymorphism in C++ Program isa.New and delete operator overloading
b.++ and – – operator overloading
c.:: operator overloading d.None
Answer: D
 
51. Run time binding is related to a.Function overriding
b.Operator overloading
c.A & B d.None Answer: A
 

05 – File Operations

Marks:-08
Content of Chapter:-
C++ stream classes, classes for file stream operations
Opening files, closing files reading from and writing to files.
Detection of end of file ,File modes.


1. Which header file is required to use file I/O operations?
a) <ifstream>
b) <ostream>
c) <fstream>
d) <iostream> Answer: c
Explanation: <fstream> header file is needed to use file I/O operations in C++. This header file contains all the file I/O operations definition.

2. Which of the following is used to create an output stream?
a) ofstream
b) ifstream
c) iostream
d) fsstream Answer: a
Explanation: ofstream is used to create an output stream in C++ file handling operations. Ofstream objects are used to read files.

3. Which of the following is used to create a stream that performs both input and output operations?
a) ofstream
b) ifstream
c) iostream
d) fstream Answer: d
Explanation: fstream is used to create a stream that performs both input and output operations in C++ file handling.

4.. Which of the following is not used as a file opening mode?
a) ios::trunc
b) ios::binary
c) ios::in
d) ios::ate Answer: a
Explanation: ios::trunc is used to truncate a file if it exists. It is not a file opening mode.

5. By default, all the files in C++ are opened in mode.
a) Text
b) Binary
c) ISCII
d) VTC Answer: a
Explanation: By default, all the files in C++ are opened in text mode. They read the file as normal text.
 
6. Which of the following is the default mode of the opening using the ofstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunk Answer: b
Explanation: By default, the file is opened in ios::out mode if the file object we are using is of ofstream class.

7. What is the return type open() method?
a) int
b) char
c) bool
d) float Answer: c
Explanation: open() method returns a bool value indicating whether the file is opened or some error has occurred.

8. Which of the following is not used to seek file pointer?
a) ios::set
b) ios::end
c) ios::cur
d) ios::beg Answer: a
Explanation: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file. ios::curr from the current position. ios::beg from the beginning.

9. Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos() Answer: a
Explanation: C++ provides tell_p() function to get the current position of the file pointer in a file.

10. Which stream class is to only write on files ?
A. ofstream
B. ifstream
C. fstream
D. iostream

Ans : A
Explanation: ofstream class is to only write on files.

11. It is not possible to combine two or more file opening mode in open () method.
A. TRUE
B. FALSE
C. May Be
D. Can't Say

Ans : B
Explanation: False, It is not possible to combine two or more file opening mode in open () method.
 

12. Which of these is the correct statement about eof() ?
A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.Ans : C
Explanation: Returns true if a file open for reading has reached the end is the correct statement about eof().

13. Which function is used to reposition the file pointer?
a) moveg()
b) seekg()
c) changep()
d) go_p() Answer: b
Explanation: seekg() function is used to reposition a file pointer in a file. The function takes the offset and relative position from where we need to shift out pointer.

14. Which of the following true about FILE *fp
A. FILE is a structure and fp is a pointer to the structure of FILE type
B. FILE is a buffered stream
C. FILE is a keyword in C for representing files and fp is a variable of FILE type
D. FILE is a stream Answer : A
Explanation: fp is a pointer of FILE type and FILE is a structure that store following information about opened file


15. Which of the following methods can be used to open a file in file handling?
A. Using Open ( )
B. Constructor method
C. Destructor method
D. Both A and B Answer : D
Explanation: Both A and B methods can be used to open a file in file handling.

16. Which operator is used to insert the data into file?
A. >>
B. <<
C. <
D. None of the above Ans : B
Explanation: You can write information to a file from your program using the stream insertion operator <<.

17. Which is correct syntax ?
A. myfile:open ("example.bin", ios::out);
B. myfile.open ("example.bin", ios::out);
C. myfile::open ("example.bin", ios::out);
D. myfile.open ("example.bin", ios:out); Answer : B
Explanation: myfile.open ("example.bin", ios::out); is correct syntax.
 

18. What is the output of this program?
using namespace std;int main ()
{
char fine, course;
cout << "Enter a word: ";fine = cin.get(); cin.sync();
course = cin.get(); cout
<< fine << endl;
cout << course << endl;
return 0;
}

A. course
B. fine
C. Returns fine 2 letter or number from the entered word
D. None of the mentioned View Answer

Answer : C
Explanation: In this program, We are using the sync function to return the fine two letters of the enteredword.

19. Which functions allow to change the location of the get and put positions ?a.sg() and sp() b.sekg() and sekp() c.gog()
and gop() d.seekg() and seekp()Answer: D

20. It is not possible to combine two or more file opening mode in open () method.
a) True
b) False
c) May be
d) None of these Answer: D
Explanation: False, It is not possible to combine two or more file opening mode in open () method.


Subscribe & Follow us on Social Media. (Second Year)

Post a Comment

Previous Post Next Post