Principles of Programming Languages MCA50317
Principles of Programming Languages MCA50317
MCA50317
3. From the point of view of the programmer what are the major
advantages of using a high-level language rather than internal machine
code or assembler language?
(a)Program portability
(b) Easy development
(c)Efficiency
Answer : b
4. 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
5. 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
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
a) 5
b) 6
c) 7
d) 8
Answer: c
95. What will be the output of the following Java code?
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a , int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
a) 6
b) 7
c) 8
d) 9
Answer: c
96. What will be the output of the following Java code?
class overload
{
int x;
double y;
void add(int a , int b)
{
x = a + b;
}
void add(double c , double d)
{
y = c + d;
}
overload()
{
this.x = 0;
this.y = 0;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 2;
double b = 3.2;
obj.add(a, a);
obj.add(b, b);
System.out.println(obj.x + " " + obj.y);
}
}
a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4
Answer: d
97. What will be the output of the following Java code?
class test
{
int a;
int b;
void meth(int i , int j)
{
i *= 2;
j /= 2;
}
}
class Output
{
public static void main(String args[])
{
test obj = new test();
int a = 10;
int b = 20;
obj.meth(a , b);
System.out.println(a + " " + b);
}
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
Answer: a
98. What will be the output of the following Java code?
class test
{
int a;
int b;
test(int i, int j)
{
a = i;
b = j;
}
void meth(test o)
{
o.a *= 2;
O.b /= 2;
}
}
class Output
{
public static void main(String args[])
{
test obj = new test(10 , 20);
obj.meth(obj);
System.out.println(obj.a + " " + obj.b);
}
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
Answer: b
99. Local variables are stored in an area called ___________
a) Heap
b) Permanent storage area
c) Free memory
d) Stack
Answer: d
100. The size of both stack and heap remains the same during run time.
a) True
b) False
Answer: b
101. Choose the statement which is incorrect with respect to dynamic
memory allocation.
a) Memory is allocated in a less structured area of memory, known as
heap
b) Used for unpredictable memory requirements
c) Execution of the program is faster than that of static memory allocation
d) Allocated memory can be changed during the run time of the program
based on the requirement of the program
Answer: c
102. Which of the following header files must necessarily be included to
use dynamic memory allocation functions?
a) stdlib.h
b) stdio.h
c) memory.h
d) dos.h
Answer: a
103. The type of linked list in which the node does not contain any
pointer or reference to the previous node is _____________
a) Circularly singly linked list
b) Singly linked list
c) Circular doubly linked list
d) Doubly linked list
Answer: b
104. Which of the following is an example for non linear data type?
a) Tree
b) Array
c) Linked list
d) Queue
Answer: a
105. Queue data structure works on the principle of ____________
a) Last In First Out (LIF0)
b) First In Last Out (FILO)
c) First In First Out (FIFO)
d) Last In Last Out (LILO)
Answer: c
106. Which of the following is an example of static memory allocation?
a) Linked list
b) Stack
c) Queue
d) Array
Answer: d
107. Array is preferred over linked list for the implementation of
________
a) Radix sort
b) Insertion sort
c) Binary search
d) Polynomial evaluation
Answer: c
108. The advantage of using linked lists over arrays is that ________
a) Linked list is an example of linear data structure
b) Insertion and deletion of an element can be done at any position in a
linked list
c) Linked list can be used to store a collection of homogenous and
heterogeneous data types
d) The size of a linked list is fixed
Answer: b
109. Which among the following best describes the Inheritance?
a) Copying the code already written
b) Using the code already written once
c) Using already defined functions in programming language
d) Using the data and functions into derived segment
Answer: d
110. How many basic types of inheritance are provided as OOP feature?
a) 4
b) 3
c) 2
d) 1
Answer: a
111. Which among the following best defines single level inheritance?
a) A class inheriting a derived class
b) A class inheriting a base class
c) A class inheriting a nested class
d) A class which gets inherited by 2 classes
Answer: b
112. Which among the following is correct for multiple inheritance?
a) class student{public: int marks;}s; class stream{int total;}; class
topper:public student, public stream{ };
b) class student{int marks;}; class stream{ }; class topper: public
student{ };
c) class student{int marks;}; class stream:public student{ };
d) class student{ }; class stream{ }; class topper{ };
Answer: a
113. Which programming language doesn’t support multiple inheritance?
a) C++ and Java
b) C and C++
c) Java and SmallTalk
d) Java
Answer: d
114. Which among the following is correct for a hierarchical inheritance?
a) Two base classes can be used to be derived into one single class
b) Two or more classes can be derived into one class
c) One base class can be derived into other two derived classes or more
d) One base class can be derived into only 2 classes
Answer: c
115. Which is the correct syntax of inheritance?
a) class derived_classname : base_classname{ /*define class body*/ };
b) class base_classname : derived_classname{ /*define class body*/ };
c) class derived_classname : access base_classname{ /*define class
body*/ };
d) class base_classname :access derived_classname{ /*define class
body*/ };
Answer: c
116. Which type of inheritance leads to diamond problem?
a) Single level
b) Multi-level
c) Multiple
d) Hierarchical
Answer: c
117. Which access type data gets derived as private member in derived
class?
a) Private
b) Public
c) Protected
d) Protected and Private
Answer: a
118. If a base class is inherited in protected access mode then which
among the following is true?
a) Public and Protected members of base class becomes protected
members of derived class
b) Only protected members become protected members of derived class
c) Private, Protected and Public all members of base, become private of
derived class
d) Only private members of base, become private of derived class
Answer: a
119. Members which are not intended to be inherited are declared as
________________
a) Public members
b) Protected members
c) Private members
d) Private or Protected members
Answer: c
120. While inheriting a class, if no access mode is specified, then which
among the following is true? (in C++)
a) It gets inherited publicly by default
b) It gets inherited protected by default
c) It gets inherited privately by default
d) It is not possible
Answer: c
121. 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
122. The private members of the base class are visible in derived class but
are not accessible directly.
a) True
b) False
Answer: a
123. How can you make the private members inheritable?
a) By making their visibility mode as public only
b) By making their visibility mode as protected only
c) By making their visibility mode as private in derived class
d) It can be done both by making the visibility mode public or protected
Answer: d
124. What is an exception?
a) Problem arising during compile time
b) Problem arising during runtime
c) Problem in syntax
d) Problem in IDE
Answer: b
125. Why do we need to handle exceptions?
a) To prevent abnormal termination of program
b) To encourage exception prone program
c) To avoid syntax errors
d) To save memory
Answer: a
126. An exception may arise when _______________
a) Input is fixed
b) Input is some constant value of program
c) Input given is invalid
d) Input is valid
Answer: c
127. If a file that needs to be opened is not found in the target location
then _____________
a) Exception will be produced
b) Exceptions are not produced
c) Exception might get produced because of syntax
d) Exceptions are not produced because of logic
Answer: a
128. Which is the universal exception handler class?
a) Object
b) Math
c) Errors
d) Exceptions
Answer: d
129. What are two exception classes in hierarchy of java exceptions
class?
a) Runtime exceptions only
b) Compile time exceptions only
c) Runtime exceptions and other exceptions
d) Other exceptions
Answer: c
130. Which are the two blocks that are used to check error and handle the
error?
a) Try and catch
b) Trying and catching
c) Do and while
d) TryDo and Check
Answer: a
131. There can be a try block without catch block but vice versa is not
possible.
a) True
b) False
Answer: a
132. How many catch blocks can a single try block can have?
a) Only 1
b) Only 2
c) Maximum 127
d) As many as required
Answer: d
133. Which among the following is not a method of Throwable class?
a) public String getMessage()
b) public Throwable getCause()
c) public Char toString()
d) public void printStackTrace()
Answer: c
134. To catch the exceptions ___________________
a) An object must be created to catch the exception
b) A variable should be created to catch the exception
c) An array should be created to catch all the exceptions
d) A string have to be created to store the exception
Answer: a
135. Multiple catch blocks __________________
a) Are mandatory for each try block
b) Can be combined into a single catch block
c) Are not possible for a try block
d) Can never be associated with a single try block
Answer: b
136. Which symbol should be used to separate the type of exception
handler classes in a single catch block?
a) ?
b) ,
c) –
d) |
Answer: d
137. Which class is used to handle the input and output exceptions?
a) InputOutput
b) InputOutputExceptions
c) IOExceptions
d) ExceptionsIO
Answer: c
138. Why do we use finally block?
a) To execute the block if exception occurred
b) To execute a code when exception is not occurred
c) To execute a code whenever required
d) To execute a code with each and every run of program
Answer: d
139. Which among the following is called first, automatically, whenever
an object is created?
a) Class
b) Constructor
c) New
d) Trigger
Answer: b
140. Which among the following is not a necessary condition for
constructors?
a) Its name must be same as that of class
b) It must not have any return type
c) It must contain a definition body
d) It can contains arguments
Answer: c
141. Which among the following is correct?
a) class student{ public: int student(){} };
b) class student{ public: void student (){} };
c) class student{ public: student{}{} };
d) class student{ public: student(){} };
Answer: d
142. In which access should a constructor be defined, so that object of the
class can be created in any function?
a) Public
b) Protected
c) Private
d) Any access specifier will work
Answer: a
143. How many types of constructors are available for use in general
(with respect to parameters)?
a) 2
b) 3
c) 4
d) 5
Answer: a
144. If a programmer defines a class and defines a default value
parameterized constructor inside it. He has not defined any default
constructor. And then he try to create the object without passing
arguments, which among the following will be correct?
a) It will not create the object (as parameterized constructor is used)
b) It will create the object (as the default arguments are passed)
c) It will not create the object (as the default constructor is not defined)
d) It will create the object (as at least some constructor is defined)
Answer: b
145. Default constructor must be defined, if parameterized constructor is
defined and the object is to be created without arguments.
a) True
b) False
Answer: a
146. If class C inherits class B. And B has inherited class A. Then while
creating the object of class C, what will be the sequence of constructors
getting called?
a) Constructor of C then B, finally of A
b) Constructor of A then C, finally of B
c) Constructor of C then A, finally B
d) Constructor of A then B, finally C
Answer: d
147. In multiple inheritance, if class C inherits two classes A and B as
follows, which class constructor will be called first?
class A{ };
class B{ };
class C: public A, public B{ };
a) A()
b) B()
c) C()
d) Can’t be determined
Answer: a
148. Which among the following is true for copy constructor?
a) The argument object is passed by reference
b) It can be defined with zero arguments
c) Used when an object is passed by value to a function
d) Used when a function returns an object
Answer: b
149. If the object is passed by value to a copy constructor?
a) Only public members will be accessible to be copied
b) That will work normally
c) Compiler will give out of memory error
d) Data stored in data members won’t be accessible
Answer: c
150. Which object will be created first?
class student
{
int marks;
};
student s1, s2, s3;
a) s1 then s2 then s3
b) s3 then s2 then s1
c) s2 then s3 then s1
d) all are created at same time
Answer: a
151. Which among the following helps to create a temporary instance?
a) Implicit call to a default constructor
b) Explicit call to a copy constructor
c) Implicit call to a parameterized constructor
d) Explicit call to a constructor
Answer: d