1. Inheritance is way to
a. Make general classes into more specific classes.
b. Pass arguments to objects of classes
c. Add features to existing classes without rewriting them.
d. Improve data-hiding and encapsulation
Answer : c)
2. Advantages of inheritance include
a. providing class growth
b. avoiding rewriting of code
c. data abstraction
d. simulation of real-world entities
Answer : b)
3. Which of the following example is unchecked exception?
a. IO Exception
b. ClassNotFoundException
c. NumberException
d. NullPointerException
Answer : d)
4. Which one of the following is a LIFO List
a. stack
b. queue
c. linked list
d. circular list
Answer : a)
5. Which of the following is a FIFO list
a. stack
b. queue
c. linked list
d. priority queue
Answer : b)
6. For implementation of recursion tree we use:
a. dequeue
b. circular queue
c. stack
d. linked list
Answer : c)
7. If the records that it’s sorting are grouped as elements less than a designed element and elements greater than the designed element, then this is:
a. quick sort
b. selection sort
c. bubble sort
d. linear search
Answer : a)
Java MCQ Set-5 Explanation
8. What is the output of the following:
public class mystery
{
public void run( )
{
int result = compute(4);
System.out.println(result);
}
public int compute(int n)
{
if(n==1)
{
return 1;
}
else
{
return n*compute(n-1);
}
}
public static void main(String [ ] args)
{
Mystery m1 = new Mystery ( );
m1.run ( );
a.22
b. 24
c.26
d. 32
Answer : b)
Java MCQ Set-5 Explanation
9. Predict the output of the following program?
void somefun(int x=24, int y=2)
{
if(x > 1)
{
if(x%y ==0)
{
System.out.println(y+ “ ”);
Somefun(x/y , y);
}
Else
someFun(x, y+1);
}
}
a. 2 2 2 3
b. 2 3 3 2
c. 2 2 2 2
d. 3 3 3 3
Answer : a)
10. Predict the output of the following program?
int check (int m, int n)
{
if ( n==1)
return –m–;
else
return ++m + check (m, –n);
}
a. 19
b. 20
c. 21
d. 22
Answer : c)