Java Set 2 (30 mcqs)

1. Which of the following can be operands of arithmetic operators?
a) Numeric
b) Boolean
c) Characters
d) Both Boolean & Characters

2. Modulus operator, %, can be applied to which of these?
a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers.
d) None of the mentioned

3. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2

4. Decrement operator, –, decreases value of variable by what number?
a) 1
b) 2
c) 3
d) 4

5. Which of these statements are incorrect?
a) Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms.
b) Assignment operators run faster than their equivalent long forms.
c) Assignment operators can be used only with numeric and character data type.
d) None

6. What is the output of this program?
1.class increment {
2.    public static void main(String args[])
3.    {
4.        double var1 = 1 + 5;
5.        double var2 = var1 / 4;
6.        int var3 = 1 + 5;
7.        int var4 = var3 / 4;
8.        System.out.print(var2 + ” ” + var4);
9.
10.    }
11.}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0

7. What is the output of this program?
1.class Modulus {
2.    public static void main(String args[])
3.    {
4.         double a = 25.64;
5.         int  b = 25;
6.         a = a % 10;
7.         b = b % 10;
8.         System.out.println(a + ” ”  + b);
9.    }
10.}
a) 5.640000000000001 5
b) 5.640000000000001 5.0
c) 5 5
d) 5 5.640000000000001

8. What is the output of this program?
1.class increment {
2.    public static void main(String args[])
3.    {
4.         int g = 3;
5.         System.out.print(++g * 8);
6.    }
7.}
a) 25
b) 24
c) 32
d) 33

9. What is the output of this program?
1.class Output {
2.    public static void main(String args[])
3.    {
4.         int x , y;
5.         x = 10;
6.         x++;
7.         –x;
8.         y = x++;
9.         System.out.println(x + ” ” + y);
10.    }
11.}
a) 11 11
b) 10 10
c) 11 10
d) 10 11

10. What is the output of this program?
1.class Output {
2.    public static void main(String args[])
3.    {
4.         int a = 1;
5.         int b = 2;
6.         int c;
7.         int d;
8.         c = ++b;
9.         d = a++;
10.         c++;
11.         b++;
12.         ++a;
13.         System.out.println(a + ” ” + b + ” ” + c);
14.    }
15.}
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4

11. Which of these class object can be used to form a dynamic array?
a) ArrayList
b) Map
c) Vector
d) Both a & b

12. Which of these are legacy classes?
a) Stack
b) Hashtable
c) Vector
d) All of the mentioned

13. Which of these is the interface of legacy?
a) Map
b) Enumeration
c) HashMap
d) Hashtable

14. What is the name of data member of class Vector which is used to store number of elements in the vector?
a) length
b) elements
c) elementCount
d) capacity

15. Which of these methods is used to add elements in vector at specific location?
a) add()
b) set()
c) AddElement()
d) addElement()

16. What is the output of this program?
1.import java.util.*;
2.class vector {
3.    public static void main(String args[]) {
4.        Vector obj = new Vector(4,2);
5.        obj.addElement(new Integer(3));
6.        obj.addElement(new Integer(2));
7.        obj.addElement(new Integer(5));
8.        System.out.println(obj.elementAt(1));
9.    }
10.}
a) 0
b) 3
c) 2
d) 5

17. What is the output of this program?
1.import java.util.*;
2.class vector {
3.    public static void main(String args[]) {
4.        Vector obj = new Vector(4,2);
5.        obj.addElement(new Integer(3));
6.        obj.addElement(new Integer(2));
7.        obj.addElement(new Integer(5));
8.        System.out.println(obj.capacity());
9.    }
10.}
a) 2
b) 3
c) 4
d) 6

18. What is the output of this program?
1.import java.util.*;
2.class vector {
3.    public static void main(String args[]) {
4.        Vector obj = new Vector(4,2);
5.        obj.addElement(new Integer(3));
6.        obj.addElement(new Integer(2));
7.        obj.addElement(new Integer(5));
8.        obj.insertElementAt(new Integer(8), 2);
9.        System.out.println(obj);
10.    }
11.}
a) [3, 2, 6]
b) [3, 2, 8]
c) [3, 2, 6, 8]
d) [3, 2, 8, 6]

19. What is the output of this program?
1.import java.util.*;
2.class vector {
3.    public static void main(String args[]) {
4.        Vector obj = new Vector(4,2);
5.        obj.addElement(new Integer(3));
6.        obj.addElement(new Integer(2));
7.        obj.addElement(new Integer(5));
8.        obj.removeAll(obj);
9.        System.out.println(obj.isEmpty());
10.    }
11.}
a) 0
b) 1
c) true
d) false

20. What is the output of this program?
1.import java.util.*;
2.class stack {
3.    public static void main(String args[]) {
4.        Stack obj = new Stack();
5.        obj.push(new Integer(3));
6.        obj.push(new Integer(2));
7.        obj.pop();
8.        obj.push(new Integer(5));
9. System.out.println(obj);
10.    }
11.}
a) [3, 5]
b) [3, 2]
c) [3, 2, 5]
d) [3, 5, 2]

21. Which of these class object uses key to store value?
a) Dictionary
b) Map
c) Hashtable
d) All if the mentioned

22. Which of these method is used to insert value and its key?
a) put()
b) set()
c) insertElement()
d) addElement()

23. Which of these is the interface of legacy is implemented by Hashtable and Dictionary classes?
a) Map
b) Enumeration
c) HashMap
d) Hashtable

24. Which of these is a class which uses String as a key to store the value in object?
a) Array
b) ArrayList
c) Dictionary
d) Properties

25. Which of these methods is used to retrieve the elements in properties object at specific location?
a) get()
b) Elementat()
c) ElementAt()
d) getProperty()

26. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3.    public static void main(String args[]) {
4.        Hashtable obj = new Hashtable();
5.        obj.put(“A”, new Integer(3));
6.        obj.put(“B”, new Integer(2));
7.        obj.put(“C”, new Integer(8));
8.        System.out.print(obj.contains(new Integer(5)));
9.    }
10.}
a) 0
b) 1
c) true
d) false

27. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3.    public static void main(String args[]) {
4.        Hashtable obj = new Hashtable();
5.        obj.put(“A”, new Integer(3));
6.        obj.put(“B”, new Integer(2));
7.        obj.put(“C”, new Integer(8));
8.        obj.clear();
9.        System.out.print(obj.size());
10.    }
11.}
a) 0
b) 1
c) 2
d) 3

28. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3.    public static void main(String args[]) {
4.        Hashtable obj = new Hashtable();
5.        obj.put(“A”, new Integer(3));
6.        obj.put(“B”, new Integer(2));
7.        obj.put(“C”, new Integer(8));
8.        obj.remove(new String(“A”));
9.        System.out.print(obj);
10.    }
11.}
a) {C=8, B=2}
b) [C=8, B=2]
c) {A=3, C=8, B=2}
d) [A=3, C=8, B=2]

29. What is the output of this program?
1.import java.util.*;
2.class hashtable {
3.    public static void main(String args[]) {
4.        Hashtable obj = new Hashtable();
5.        obj.put(“A”, new Integer(3));
6.        obj.put(“B”, new Integer(2));
7.        obj.put(“C”, new Integer(8));
8.        System.out.print(obj.toString());
9.    }
10.}
a) {C=8, B=2}
b) [C=8, B=2]
c) {A=3, C=8, B=2}
d) [A=3, C=8, B=2]

30. What is the output of this program?
1.import java.util.*;
2.class properties {
3.    public static void main(String args[]) {
4.        Properties obj = new Properties();
5.        obj.put(“AB”, new Integer(3));
6.        obj.put(“BC”, new Integer(2));
7.        obj.put(“CD”, new Integer(8));
8.        System.out.print(obj.keySet());
9.    }
10.}
a) {AB, BC, CD}
b) [AB, BC, CD]
c) [3, 2, 8]
d) {3, 2, 8}

Answers

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

 

Spread the love

Leave a Comment

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