0% found this document useful (0 votes)
56 views18 pages

Structuring of Program: Unit III

This document contains 32 multiple choice questions about object-oriented programming concepts like encapsulation, inheritance, polymorphism, and abstraction. It also includes questions about Java programming language fundamentals like classes, objects, methods, and threads. The questions cover defining features of OOP like hierarchical classification and inheritance, access specifiers, and memory allocation using new operator in Java.

Uploaded by

Samara Sequeira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views18 pages

Structuring of Program: Unit III

This document contains 32 multiple choice questions about object-oriented programming concepts like encapsulation, inheritance, polymorphism, and abstraction. It also includes questions about Java programming language fundamentals like classes, objects, methods, and threads. The questions cover defining features of OOP like hierarchical classification and inheritance, access specifiers, and memory allocation using new operator in Java.

Uploaded by

Samara Sequeira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Unit III

STRUCTURING OF PROGRAM

MULTIPLE CHOICE QUESTIONS


1. Which of the following is the functionality of ‘Data Abstraction’?
(a) Reduce Complexity (b) Binds together code and data
(c) Parallelism (d) None of the mentioned
Answer : a
Explanation : An essential element of Object Oriented Programming is ‘Data
Abstraction’ which means hiding things. Complexity is managed through abstraction.
2. Which of the following mechanisms is/are provided by Object Oriented Language to
implement Object Oriented Model?
(a) Encapsulation (b) Inheritance
(c) Polymorphism (d) All of the mentioned
Answer : d
Explanation : None.
3. Which of these is the functionality of ‘Encapsulation’?
(a) Binds together code and data
(b) Using single interface for general class of actions.
(c) Reduce Complexity
(d) All of the mentioned
Answer : a
Explanation : ‘Encapsulation’ acts as protective wrapper that prevents code and data
from being accessed by other code defined outside the wrapper.
4. What is ‘Basis of Encapsulation’?
(a) object (b) class
(c) method (d) all of the mentioned
Answer : d
Explanation : Encapsulation is the mechanism that binds together code and data it
manipulates, and keeps both safe from outside interface and misuse. Class, which
contains data members and methods is used to implement Encapsulation.

Unit III | 3.1


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

5. How will a class protect the code inside it?


(a) Using Access specifiers (b) Abstraction
(c) Use of Inheritance (d) All of the mentioned
Answer : a
Explanation : Each method or variable in a class may be marked ‘public’ or ‘private’.
They are called Access Specifiers.
6. What is the output of this program?
class Test {
int a;
public int b;
private int c;
}
class AcessTest {
public static void main(String args[])
{
Test ob = new Test();
ob.a = 10;
ob.b = 20;
ob.c = 30;
System.out.println(" Output :a, b, and c" + ob.a + " " + ob.b + " " + ob.c”);
}
}
(a) Compilation error (b) Run time error
(c) Output : a, b and c 10 20 30 (d) None of the mentioned
Answer : a
Explanation : Private members of a class cannot be accessed directly. In the above
program, the variable c is a private member of class ‘Test’ and can only be accessed
through its methods.
7. Which of the following is a mechanism by which object acquires the properties of
another object?
(a) Encapsulation (b) Abstraction
(c) Inheritance (d) Polymorphism
Answer : c
Explanation : ‘Inheritance’ is the mechanism provided by Object Oriented Language,
which helps an object to acquire the properties of another object usually child object
from parent object.
Unit III | 3.2
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

8. Which of the following supports the concept of hierarchical classification?


(a) Polymorphism (b) Encapsulation
(c) Abstraction (d) Inheritance
Answer : d
Explanation : Use of Hierarchical classification avoids defining the properities of
object explicitly at each level which have acquired their properties from higher levels.
9. Which Keyword from the following is used to inherit properties from one class into
another?
(a) extends (b) subclasses
(c) native (d) all of the mentioned
Answer : a
Explanation : None.
10. Which of the following concept is often expressed by the phrase, ‘One interface,
multiple methods’?
(a) Abstraction (b) Polymorphism
(c) Inheritance (d) Encapsulation
Answer : b
Explanation : None.
11. Who is known as father of Java Programming Language?
(a) James Gosling (b) M. P Java
(c) Charel Babbage (d) Blais Pascal
Answer : a
12. In java control statements break, continue, return, try-catch-finally and assert belongs
to?
(a) Selection statements (b) Loop Statements
(c) Transfer statements (d) Pause Statement
Answer : c
13. Which provides runtime environment for java byte code to be executed?
(a) JDK (b) JVM (c) JRE (d) JAVAC
Answer : b
14. What is byte code in Java?
(a) Code generated by a Java compiler
(b) Code generated by a Java Virtual Machine
(c) Name of Java source code file
(d) Block of code written inside a class
Answer : a
Unit III | 3.3
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

15. Which of the following are not Java keywords ?


(a) double (b) switch (c) then (d) instance of
Answer : c
16. Which of these have highest precedence?
(a) () (b) ++ (c) * (d) >
Answer : a
17. Which of these is returned by operator '&' ?
(a) Integer (b) Character (c) Boolean (d) Float
Answer : b
18. Data type long literals are appended by _____
(a) Uppercase L (b) Lowercase L
(c) Long (d) Both A and B
Answer : d
19. Which variables are created when an object is created with the use of the keyword
'new' and destroyed when the object is destroyed?
(a) Local variables (b) Instance variables
(c) Class Variables (d) Static variables
Answer : b
20. Java language was initially called as _____
(a) Sumatra (b) J++ (c) Oak (d) Pine
Answer : c
21. What is garbage collection in the context of Java?
(a) Java deletes all unused java files on the system.
(b) Memory used by the object with no reference is automatically reclaimed.
(c) The JVM cleans output of Java program with error.
(d) Any unused package in a program automatically gets deleted.
Answer : b
22. Which one is a template for creating different objects ?
(a) An Array (b) A class
(c) Interface (d) Method
Answer : b
23. Which symbol is used to contain the values of automatically initialized arrays?
(a) Brackets (b) Braces (c) Parentheses (d) Comma
Answer : b
Unit III | 3.4
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

24. Which one is true about a constructor ?


(a) A constructor must have the same name as the class it is declared within.
(b) A constructor is used to create objects.
(c) A constructor may be declared private
(d) All of the above
Answer : d
25. Which of these operators is used to allocate memory to array variable in Java?
(a) alloc (b) malloc (c) new malloc (d) new
Answer : d
26. Which of these is not a bitwise operator?
(a) &' Operator (b) &=' Operator
(c) |=' Operator (d) <=' Operator
Answer : d
27. Which of these is returned by Greater Than, Less Than and Equal To (i.e Relational)
operator ?
(a) Float (b) Integer (c) Boolean (d) Double
Answer : c
28. Which statement transfer execution to different parts of your code based on the
value of an expression?
(a) If (b) Switch (c) Nested-if (d) if-else-if
Answer : b
29. Modulus operator (%) can be applied to which of these?
(a) Integers (b) Floating - point numbers
(c) Both A and B (d) None of These
Answer : c
30. What feature of OOP has a super-class sub-class concept?
(a) Hierarchical inheritance
(b) Single inheritance
(c) Multiple inheritances
(d) Multilevel inheritance
Answer : a
31. Which of the following are not the methods of the Thread class?
(a) yield() (b) sleep(long msec)
(c) go() (d) stop()
Answer : c
Unit III | 3.5
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

32. Division operator has _____ precedence over multiplication operator.


(a) Highest (b) Least (c) Equal (d) None of These
Answer : c
33. What is the full form of JVM ?
(a) Java Very Large Machine (b) Java Verified Machine
(c) Java Very Small Machine (d) Java Virtual Machine
Answer : d
34. In Java code, the line that begins with /* and ends with */ is known as?
(a) Multiline comment (b) Single line comment
(c) Both (a) and (b) (d) None of these
Answer : a
35. Which of the following are not Java modifiers?
(a) public (b) private (c) friendly (d) transient
Answer : c
36. Which of the following factors supports the statement that the 'reusability' is a
desirable feature of a language?
(a) It decreases the testing time. (b) It lowers the maintenance cost.
(c) It reduces the compilation time. (d) Both 1 and 2.
Answer : d
37. Which of these can be used to fully abstract a class from its implementation?
(a) Objects (b) Packages
(c) Interfaces (d) None of the Mentioned.
Answer : c
Explanation : None.
38. Which of these access specifiers can be used for an interface?
(a) Public (b) Protected
(c) private (d) All of the mentioned
Answer : d
39. Which of these keywords is used by a class to use an interface defined previously?
(a) import (b) Import (c) implements (d) Implements
Answer : c
Explanation : interface is inherited by a class using implements.

Unit III | 3.6


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

40. Which of the following is correct way of implementing an interface salary by class
manager?
(a) class manager extends salary {}
(b) class manager implements salary {}
(c) class manager imports salary {}
(d) None of the mentioned.
Answer : b
Explanation : None.
41. Which of the following is incorrect statement about packages?
(a) Interfaces specifies what class must do but not how it does.
(b) Interfaces are specified public if they are to be accessed by any code in the
program.
(c) All variables in interface are implicitly final and static.
(d) All variables are static and methods are public if interface is defined pubic.
Answer : d
Explanation : All methods and variables are implicitly public if interface is declared
public.
42. Which of the following package stores all the standard java classes?
(a) lang (b) java (c) util (d) java packages
Answer : b
Explanation : None.
43. What is the output of this program?
interface calculate {
void cal(int item);
}
class display implements calculate {
int x;
public void cal(int item) {
x = item * item;
}
}
class interfaces {
public static void main(String args[]) {
display arr = new display;
arr.x = 0;
Unit III | 3.7
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

arr.cal(2);
System.out.print(arr.x);
}
}
(a) 0 (b) 2
(c) 4 (d) None of the mentioned
Answer : c
Explanation : None.
Output :
$ javac interfaces.java
$ java interfaces
4
44. What is the output of this program?
interface calculate {
void cal(int item);
}
class displayA implements calculate {
int x;
public void cal(int item) {
x = item * item;
}
}
class displayB implements calculate {
int x;
public void cal(int item) {
x = item / item;
}
}
class interfaces {
public static void main(String args[]) {
displayA arr1 = new displayA;
displayB arr2 = new displayB;
arr1.x = 0;
arr2.x = 0;
Unit III | 3.8
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

arr1.cal(2);
arr2.cal(2);
System.out.print(arr1.x + " " + arr2.x);
}
}
(a) 00 (b) 2 2 (c) 4 1 (d) 1 4
Answer : c
Explanation : class displayA implements the interface calculate by doubling the value
of item, where as class displayB implements the interface by dividing item by item,
therefore variable x of class displayA stores 4 and variable x of class displayB stores 1.
Output :
$ javac interfaces.java
$ java interfaces
41
45. What is the output of this program?
interface calculate {
int VAR = 0;
void cal(int item);
}
class display implements calculate {
int x;
public void cal(int item) {
if (item<2)
x = VAR;
else
x = item * item;
}
}
class interfaces {
public static void main(String args[]) {
display[] arr=new display[3];
for(int i=0;i<3;i++)
arr[i]=new display();

Unit III | 3.9


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

arr[0].cal(0);
arr[1].cal(1);
arr[2].cal(2);
System.out.print(arr[0].x+" " + arr[1].x + " " + arr[2].x); } }
(a) 012 (b) 0 2 4 (c) 0 0 4 (d) 0 1 4
Answer : c
Explanation : None.
Output :
$ javac interfaces.java
$ java interfaces
004
46. What will be the output of following program?
#include<iostream.h>
void main()
{
float x;
x=(float)9/2;
cout<<x;
}
(a) 4.5 (b) 4.0 (c) 4 (d) 5
Answer : a
47. The term _____ means the ability to take many forms.
(a) Inheritance (b) Polymorphism (c) Member function (d) Encapsulation
Answer : b
48. Runtime polymorphism is achieved by
(a) Friend function (b) Virtual function
(c) Operator overloading (d) Function overloading
Answer : b
49. Access to private data
(a) Restricted to methods of the same class
(b) Restricted to methods of other classes
(c) Available to methods of the same class and other classes
(d) Not an issue because the program will not compile
Answer : b

Unit III | 3.10


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

50. Additional information sent when an exception is thrown may be placed in


(a) The throw keyword (b) The function that caused the error
(c) The catch block (d) An object of the exception class
Answer : c
51. A static data member is given a value
(a) Within the class definition (b) Outside the class definition
(c) When the program is executed (d) Never
Answer : d
52. What will be the result of the expression 13 and 25?
(a) 38 (b) 25 (c) 9 (d) 12
Answer : c
53. In a class specifier ,data or function designated private are accessible
(a) To any function in the program
(b) Only if you the password
(c) To member functions of that class
(d) Only to public members of the class
Answer : c
54. Which of the statements are true ?
I. Function overloading is done at compile time.
II. Protected members are accessible to the member of derived class.
III. A derived class inherits constructors and destructors.
IV. A friend function can be called like a normal function.
V. Nested class is a derived class.
(a) I, II, III (b) II, III, V (c) III, IV, V (d) I, II, IV
Answer : d
55. At which point of time a variable comes into existence in memory is determined by
its
(a) Scope (b) Storage class (c) Data type (d) All of the above
Answer : b
56. When the compiler cannot differentiate between two overloaded constructors, they
are called
(a) Overloaded (b) Destructed (c) Ambiguous (d) Dubious
Answer : c
Unit III | 3.11
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

57. The actual source code for implementing a template function is created when
(a) The declaration of function appears.
(b) The function is invoked.
(c) The definition of the function appears.
(d) None of the above.
Answer : b
58. Usually a pure virtual function
(a) Has complete function body
(b) Will never be called
(c) Will be called only to delete an object
(d) Is defined only in derived class
Answer : d
59. Which of the following is the valid class declaration header for the derived class d
with base classes b1 and b2?
(a) class d : public b1, public b2 (b) class d : class b1, class b2
(c) class d : public b1, b2 (d) class d : b1, b2
Answer : a
60. The process of extracting the relevant attributes of an object is known as
(a) Polymorphism (b) Inheritence
(c) Abstraction (d) Data hiding
Answer : b
61. What features make C++ so powerful ?
(a) Easy implementation (b) Reusing old code
(c) Reusing old code (d) All of the above
Answer : d
62. Which of the following operator can be overloaded through friend function?
(a) -> (b) = (c) ( ) (d) *
Answer : d
63. The keyword friend does not appear in
(a) The class allowing access to another class
(b) The class desiring access to another class
(c) The private section of a class
(d) The public section of a class
Answer : c
Unit III | 3.12
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

64. Exception handling is targeted at


(a) Run-time error (b) Compile time error
(c) Logical error (d) All of the above
Answer : a
65. Function templates can accept
(a) Any type of parameters
(b) Only one parameter
(c) Only parameters of the basic type
(d) Only parameters of the derived type
Answer : c
66. If the variable count exceeds 100, a single statement that prints “Too many” is
(a) if (count<100) cout << “Too many”;
(b) if (count>100) cout >> “Too many”;
(c) if (count>100) cout << “Too many”;
(d) None of these.
Answer : c
67. The mechanism that binds code and data together and keeps them secure from
outside world is known as
(a) Abstraction (b) Inheritance (c) Encapsulation (d) Polymorphism
Answer : c
68. The operator << when overloaded in a class
(a) must be a member function (b) must be a non member function
(c) can be both (a) and (b) above (d) cannot be overloaded
Answer : c
69. To access the public function fbase() in the base class, a statement in a derived class
function fder() uses the statement.fbase();
(a) fbase(); (b) fder();
(c) base::fbase(); (d) der::fder();
Answer : a
70. In which case is it mandatory to provide a destructor in a class?
(a) Almost in every class
(b) Class for which two or more than two objects will be created
(c) Class for which copy constructor is defined
(d) Class whose objects will be created dynamically
Answer : d

Unit III | 3.13


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

71. _____ members of a base class are never accessible to a derived class.
(a) Public (b) Private (c) Protected (d) (a), (b) and (c)
Answer : b
72. What is the error in the following code?
class t
{
virtual void print();
}
(a) No error
(b) Function print() should be declared as static.
(c) Function print() should be defined.
(d) Class t should contain data members.
Answer : a
73. It is possible to declare as a friend
(a) A member function (b) A global function
(c) A class (d) All of the above
Answer : d
74. A struct is the same as a class except that
(a) There are no member functions
(b) All members are public
(c) Cannot be used in inheritance hierarchy
(d) It does have a this pointer
Answer : c
75. C++ was originally developed by
(a) Clocksin and Melish (b) Donald E.Knuth
(c) Sir Richard Hadlee (d) Bjarne Stroustrup
Answer : d
76. What is the output of the following code
char symbol[3]={‘a’,‘b’,‘c’};
for (int index=0; index<3; index++)
cout << symbol [index];
(a) abc (b) “abc” (c) abc (d) ‘abc’
Answer : c

Unit III | 3.14


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

77. If we create a file by ‘ifstream’, then the default mode of the file is _____
(a) ios :: out (b) ios :: in (c) ios :: app (d) ios :: binary
Answer : b
78. The following can be declared as friend in a class
(a) An object
(b) A class
(c) A public data member
(d) A private data member
Answer : b
79. The polymorphism can be characterized by the phrase
(a) One interface,multiple methods
(b) Multiple interfaces,one method
(c) One interface,one method
(d) None of the above
Answer : a
80. A virtual class is the same as
(a) An abstract class (b) A class with a virtual function
(c) A base class (d) None of the above
Answer : d
81. Member functions, when defined within the class specification
(a) Are always inline
(b) Are not inline
(c) Are inline by default, unless they are too big or too complicated
(d) Are not inline by default.
Answer : a
82. Assume that we have constructor functions for both base class and derived class.
Now consider the declaration in main( ). Base * P = New Derived; in what sequence
will the constructor be called ?
(a) Derived class constructor followed by Base class constructor.
(b) Base class constructor followed by derived class constructor.
(c) Base class constructor will not be called.
(d) Base class constructor will not be called.
Answer : b
83. The operator that cannot be overloaded is
(a) ++ (b) : : (c) ~ (d) ( )
Answer : b
Unit III | 3.15
PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

84. Which of the following declarations are illegal?


(a) void *ptr; (b) char *str = “hello”;
(c) char str = “hello”; (d) const *int p1;
Answer : c
85. Identify the operator that is NOT used with pointers
(a) -> (b) & (c) * (d) >>
Answer : d
86. Which of the following statements is NOT valid about operator overloading?
(a) Only existing operators can be overloaded
(b) Overloaded operator must have at least one operand of its class type
(c) The overloaded operators follow the syntax rules of the original operator
(d) None of the above
Answer : d
87. Overloading a postfix increment operator by means of a member function takes
(a) No argument (b) One argument
(c) Two arguments (d) Three arguments
Answer : a
88. Which of the following will produce a value 10 if x = 9.7?
(a) floor(x) (b) abs(x) (c) log(x) (d) ceil(x)
Answer : d
89. Which of the following is not the characteristic of constructor?
(a) They should be declared in the public section.
(b) They do not have return type.
(c) They can not be inherited.
(d) They can be virtual.
Answer : d
90. You may override the class access specifiers
(a) Public members
(b) Public and protected members
(c) Any specific class members you choose
(d) No class members
Answer : c
91. You separated a derived class name from its access specifier with
(a) A colon (b) Two colons (c) Atleast one space (d) A semi colon
Answer : b

Unit III | 3.16


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

92. Consider the following statements :


int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?
(a) 22 (b) 37 (c) 7 (d) 5
Answer : b
93. A friend function to a class, C cannot access
(a) Private data members and member functions
(b) Public data members and member functions
(c) Protected data members and member functions
(d) The data members of the derived class of C
Answer : d
94. The members of a class by default are
(a) Public (b) Protected
(c) Private (d) Mandatory to specify
Answer : c
95. Which operator is used to signify the namespace?
(a) conditional operator (b) ternary operator
(c) scope operator (d) none of the mentioned
Answer : c
Explanation : scope operator
96. Identify the correct statement
(a) Namespace is used to group class, objects and functions.
(b) Namespace is used to mark the beginning of the program.
(c) Namespace is used to seperate the class, objects.
(d) None of the above
Answer : a
Explanation : Namespace allow you to group class, objects and functions. It is used
to divide the global scope into the sub-scopes.
97. What is the use of Namespace?
(a) To encapsulate the data (b) To structure a program into logical units.
(c) Both a and b (d) none of the mentioned
Answer : b
Explanation : The main aim of the namespace is to understand the logical units of
the program and to make the program so robust.

Unit III | 3.17


PRINCIPLES OF PROGRAMMING LANGUAGES (SE COMP.) STRUCTURING OF PROGRAM

98. What is the general syntax for accessing the namespace variable?
(a) namespaceid::operator (b) namespace,operator
(c) namespace#operator (d) none of the mentioned
Answer : a
Explanation : namespaceid::operator
99. Which keyword is used to access the variable in namespace?
(a) using (b) dynamic (c) const (d) static
Answer : a
100. Which of these keywords is used to define interfaces in Java?
(a) interface (b) Interface (c) intf (d) Intf
Answer : a
Explanation : None.

Unit III | 3.18

You might also like