Java Set 6 (30 mcqs)

1. What is Recursion in Java?
a) Recursion is a class.
b) Recursion is a process of defining a method that calls other methods repeatedly.
c) Recursion is a process of defining a method that calls itself repeatedly.
d) Recursion is a process of defining a method that calls other methods which in turn call again this method.

2. Which of these data types is used by operating system to manage the Recursion in Java?
a) Array
b) Stack
c) Queue
d) Tree

3. Which of these will happen if recursive method does not have a base case?
a) An infinite loop occurs
b) System stops the program after some time.
c) After 1000000 calls it will be automatically stopped.
d) None of the mentioned

4. Which of these is not a correct statement?
a) A recursive method must have a base case.
b) Recursion always uses stack.
c) Recursive methods are faster that programmers written loop to call the function repeatedly using a stack.
d) Recursion is managed by Java’s Run – Time environment.

5. Which of these packages contains the exception Stackoverflow in Java?
a) java.lang
b) java.util
c) java.io
d) java.system

6. What is the output of this program?
1.class recursion {
2.    int func (int n) {
3.        int result;
4.        result = func (n – 1);
5.        return result;
6.    }
7.}
8.class Output {
9.    public static void main(String args[]) {
10.        recursion obj = new recursion() ;
11.        System.out.print(obj.func(12));
12.    }
13.}
a) 0
b) 1
c) Compilation Error
d) Runtime Error

7. What is the output of this program?
1.class recursion {
2.    int func (int n) {
3.        int result;
4.        if (n == 1)
5.            return 1;
6.        result = func (n – 1);
7.        return result;
8.    }
9.}
10.class Output {
11.    public static void main(String args[]) {
12.        recursion obj = new recursion() ;
13.        System.out.print(obj.func(5));
14.    }
15.}
a) 0
b) 1
c) 120
d) None of the mentioned

8. What is the output of this program?
1.class recursion {
2.    int fact(int n) {
3.        int result;
4.        if (n == 1)
5.            return 1;
6.        result = fact(n – 1) * n;
7.        return result;
8.    }
9.}
10.class Output {
11.    public static void main(String args[]) {
12.        recursion obj = new recursion() ;
13.        System.out.print(obj.fact(5));
14.    }
15.}
a) 24
b) 30
c) 120
d) 720

9. What is the output of this program?
1.class recursion {
2.    int fact(int n) {
3.        int result;
4.        if (n == 1)
5.            return 1;
6.        result = fact(n – 1) * n;
7.        return result;
8.    }
9.}
10.class Output {
11.    public static void main(String args[]) {
12.        recursion obj = new recursion() ;
13.        System.out.print(obj.fact(1));
14.    }
15.}
a) 1
b) 30
c) 120
d) Runtime Error

10. What is the output of this program?
1.class recursion {
2.    int fact(int n) {
3.        int result;
4.        if (n == 1)
5.            return 1;
6.        result = fact(n – 1) * n;
7.        return result;
8.    }
9.}
10.class Output {
11.    public static void main(String args[]) {
12.        recursion obj = new recursion() ;
13.        System.out.print(obj.fact(6));
14.    }
15.}
a) 1
b) 30
c) 120
d) 720

11. What is use of Observable class?
a) It is used to create global subclasses
b) It is used to create classes that other part of program can observe.
c) It is used to create classes that can be accessed by other parts of program.
d) It is used to create methods that can be accessed by other parts of program.

12. Which of these methods is used to notify observer the change in observed object?
a) update()
b) notify()
c) check()
d) observed()

13. Which of these methods calls update() method?
a) notify()
b) observeObject()
c) updateObserver()
d) notifyObserver()

14. Which of these methods is called when observed object has changed?
a) setChanged()
b) update()
c) notifyObserver()
d) All of the mentioned

15. Which of these classes can schedule task for execution in future?
a) Thread
b) Timer
c) System
d) Observer

16. Which of these interfaces is implemented by TimerTask class?
a) Runnable
b) Thread
c) Observer
d) ThreadCount

17. Which of these package provides the ability to read and write in Zip format?
a) java.lang
b) java.io
c) java.util.zip
d) java.util.zar

18. What is the output of this program?
1.import java.util.*;
2.class LOCALE_CLASS {
3.    public static void main(String args[]) {
4.        Locale obj = new Locale(“HINDI”, “INDIA”) ;
5.        System.out.print(obj.getCountry());
6.    }
7.}
a) India
b) INDIA
c) Compilation Error
d) Nothing is displayed

Output:
$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS
INDIA
19. What is the output of this program?
1.import java.util.*;
2.class LOCALE_CLASS {
3.    public static void main(String args[]) {
4.        Locale obj = new Locale(“HINDI”) ;
5.        System.out.print(obj.getDisplayLanguage());
6.    }
7.}
a) India
b) INDIA
c) HINDI
d) Nothing is displayed

Output:
$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS
HINDI
20. What is the output of this program?
1.import java.util.*;
2.class LOCALE_CLASS {
3.    public static void main(String args[]) {
4.        Locale obj = new Locale(“HINDI”, “INDIA”) ;
5.        System.out.print(obj.getDisplayLanguage());
6.    }
7.}
a) India
b) INDIA
c) HINDI
d) Nothing is displayed

21. Which of these class provides various types of rounding functions?
a) Math
b) Process
c) System
d) Object

22. Which of these method return a smallest whole number greater than or equal to variable X?
a) double ciel(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)

23. Which of these method return a largest whole number less than or equal to variable X?
a) double ciel(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)

24. Which of these method is a rounding function of Math class?
a) max()
b) min()
c) abs()
d) rint()

25. Which of these class contains only floating point functions?
a) Math
b) Process
c) System
d) Object

26. Which of function return absolute value of a variable?
a) abs()
b) absolute()
c) absolutevariable()
d) None of the mentioned

27. What is the output of this program?
1.class A {
2.     int x;
3.     int y;
4.     void display() {
5.          System.out.print(x + ” ” + y);
6.     }
7.}
8.class Output {
9.     public static void main(String args[]) {
10.         A obj1 = new A();
11.         A obj2 = new A();
12.         obj1.x = 1;
13.         obj1.y = 2;
14.         obj2 = obj1.clone();
15.         obj1.display();
16.         obj2.display();
17.    }
18.}
a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) System Dependent

28. What is the output of this program?
1.class Output {
2.     public static void main(String args[]) {
3.         double x = 3.14;
4.         int y = (int) Math.abs(x);
5.         System.out.print(y);
6.    }
7.}
a) 0
b) 3
c) 3.0
d) 3.1

29. What is the output of this program?
1.class Output {
2.     public static void main(String args[]) {
3.         double x = 3.14;
4.         int y = (int) Math.ceil(x);
5.         System.out.print(y);
6.    }
7.}
a) 0
b) 3
c) 3.0
d) 4

30. What is the output of this program?
1.class Output {
2.     public static void main(String args[]) {
3.         double x = 3.14;
4.         int y = (int) Math.floor(x);
5.         System.out.print(y);
6.    }
7.}
a) 0
b) 3
c) 3.0
d) 4

Answers

1-b 2-b 3-a 4-d 5-a
6-d 7-b 8-c 9-a 10-d
11-b 12-a 13-d 14-d 15-b
16-a 17-c 18-b 19-c 20-c
21-a 22-a 23-b 24-d 25-a
26-a 27-b 28-b 29-d 30-d

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

shares