wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Global Logic (JAVA)

Total questions: 125

Worksheet time: 1hrs 22mins

Name
Class
Date
1.

-Contains no duplicate elements.

-Can contain at most one Null value.

-Elements are not key-value pairs.

-Accessing an element can be almost as fast as performing a similar operation on an array.


Which of these classes provides the specified features?

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

LinkedHashMap

e)

HashMap

2.

Which of the following statement about Set is true?

a)

A HashSet cannot have a null value.

b)

Set allows duplicate values.

c)

Set allows null values but only single occurrence.

d)

Set extends the Java.util.collection interface.

3.

-Entries are organized as key/value pairs.

-Duplicate entries replace old entries.

-Entries are sorted using a Comparator or the Comparable interface.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

SortedSet

e)

SortedMap

4.
a)

{1=C, 2=JavaEE, 4=Python, 3=PHP}

b)

{1=C, 2=JavaSE, 3=Python, 4=PHP}

c)

{1=C, 2=JavaEE, 3=Python, 4=PHP}

d)

{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}

e)

NullPointerException

5.
a)

{null=null, a=null, b=JavaSE, c=PHP, d=Python}

b)

{a=null, b=JavaSE, c=PHP, d=Python}

c)

{b=JavaSE, c=PHP, d=Python}

d)

Compilation Fails

6.

-Entries are not organized as key/value pairs.

-Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

None of the above

7.

Which of the following is/are correct statements?

a)

HashSet class implements the Set interface

b)

HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.

c)

HashSet permits to have a single null value.

d)

HashMap does not allow duplicate keys however it allows to have duplicate values.

e)

HashMap and HashSet are threadsafe

8.

Which of the following statement(s) is/are TRUE?

a)

Both HashMap and HashSet are not synchronized.

b)

HashMap does not allow duplicate keys however it allows to have duplicate values.

c)

HashMap permits single null key and any number of null values.

d)

Both HashMap and HashSet are synchronized.

9.

Which of the following statement(s) is/are FALSE?

a)

TreeSet does not preserve the insertion order of elements but elements are sorted by keys.

b)

Objects in a TreeSet are stored in a sorted and ascending order.

c)

TreeSet does not allow to insert Heterogeneous objects. It will throw classCastException at Runtime if trying to add hetrogeneous objects.

d)

Comparator is note provided for TreeSet.

10.

Which of the following is/are FALSE about HashMap in java?

a)

It provides the basic implementation of Map interface of Java.

b)

HashMap doesn’t allow duplicate keys but allows duplicate values.

c)

HashMap allows null key also but only once and multiple null values.

d)

Unsynchronized.

e)

Synchronized

11.

List listNames = new ArrayList();

listNames.add("Tom");

listNames.add("Mary");

listNames.add("Peter");


String name2 = (String) listNames.get(1);

System.out.println(name2);

What is the output of the above code

a)

Tom

b)

Mary

c)

Peter

d)

raises Exception

12.

Which of these return type of hasNext() method of an iterator?

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

13.

 What will be the output of the  Java program?

a)

{0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

{0, 1, 2, 3, 4}

d)

{0, 0, 0, 3, 4}

14.

Which of these interface is not part of Java’s collection framework?

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

15.

What is Collection in Java?

a)

A group of objects

b)

A group of classes

c)

A group of interfaces

d)

None of the mentioned

16.

What is Collection in Java?

a)

A group of objects

b)

A group of classes

c)

A group of interfaces

d)

None of the mentioned

17.

Which of these interface is not part of Java’s collection framework?

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

18.

 What will be the output of the  Java program?

a)

{0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

{0, 1, 2, 3, 4}

d)

{0, 0, 0, 3, 4}

19.

Which of these return type of hasNext() method of an iterator?

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

20.

Which of these exceptions is thrown by remover() method?

a)

IOException

b)

SystemException

c)

ObjectNotFoundExeception

d)

IllegalStateException

21.

Which of these methods deletes all the elements from invoking collection?

a)

clear();

b)

reset();

c)

delete();

d)

remove();

22.

Which of these interface declares core method that all collections will have?

a)

Collection

b)

EventListner

c)

Comparator

d)

Set

e)

List

23.

Which of these is an incorrect form of using method max() to obtain maximum element?

a)

max(Collection c)

b)

max(Collection c, Comparator comp)

c)

max(Comparator comp)

d)

max(List c)

24.

Which of these methods can convert an object into a List?

a)

SetList()

b)

ConvertList()

c)

CopyList()

d)

singletonList()

25.

Which of these is true about unmodifiableCollection() method?

a)

unmodifiableCollection() returns a collection that cannot be modified.

b)

unmodifiableCollection() method is available only for List and Set.

c)

unmodifiableCollection() is defined in Collection class.

d)

None of the mentioned.

26.

Which of these is static variable defined in Collections?

a)

EMPTY_SET

b)

EMPTY_LIST

c)

EMPTY_MAP

d)

All of the mentioned

27.

What implementation of Iterator can traverse a collection in both directions?

a)

Iterator

b)

ListIterator

c)

SetIterator

d)

MapIterator

28.

Which is faster and uses less memory?

a)

ListEnumeration

b)

Iterator

c)

Enumeration

d)

ListIterator

29.

What will be output of given code

a)

a followed by concurrentModification Exception

b)

a b c

c)

a b

d)

a c

30.

Which interface does java.util.Hashtable implement?

a)

Java.util.Map

b)

Java.util.List

c)

Java.util.HashTable

d)

Java.util.Collection

31.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.

Which interface provides that capability?

a)

java.util.Map

b)

java.util.Set

c)

java.util.List

d)

java.util.Collection

32.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.

Which interface provides that capability?

a)

java.util.Map

b)

java.util.Set

c)

java.util.List

d)

java.util.Collection

33.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

a)

java.util.HashSet

b)

java.util.LinkedHashSet

c)

java.util.List

d)

java.util.ArrayList

34.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

a)

java.util.HashSet

b)

java.util.LinkedHashSet

c)

java.util.List

d)

java.util.ArrayList

35.

The default capacity of a Vector is:

a)

10

b)

12

c)

8

d)

0

36.

The Comparable interface contains which called?

a)

toCompare

b)

compare

c)

compareTo

d)

compareWith

37.

Find the output

public class TreeMapTest {

public static void main(String args[]) {

Map<Integer, String> m = new TreeMap<Integer, String>();

m.put(11, "audi");

m.put(null, null);

m.put(11, "bmw");

m.put(null, "ferrari");

System.out.println(m.size());

System.out.println(m);

}

a)

Nullpointer exception

b)

compiler error

c)

2

d)

Null value

38.

public class MyClass {

public static void main(String args[]) {

Map<String, String> hashMap = new HashMap<String, String>();

hashMap.put(new String("a"), "audi");

hashMap.put(new String("a"), "ferrari");

System.out.println(hashMap);

}

}

a)

a=audi

b)

a=audi

a=ferrari

c)

a=ferrari

d)

Run time Error

39.

Deque and Queue are derived from

a)

Abstract class

b)

Collection

c)

Abstactcollection

d)

List

40.

What will be output of given code

a)

1 2 3

b)

1 followed by exception

c)

Compile time error

d)

run time error

41.

Which is best suited to a multi-threaded environment?

a)

WeakHashMap

b)

Hashtable

c)

HashMap

d)

ConcurrentHashMap

42.

TreeMap implements?

a)

Dictionary

b)

HashMap

c)

AbstractMap

d)

NavigableMap

43.

Which of these is synchronized?

a)

TreeMap

b)

HashMap

c)

Hashtable

d)

All of the above

44.

TreeMap

a)

doesn't allow null key

b)

allow many null values

c)

Both

d)

allow many null key

45.

How can you sort given HashMap on basis of values

a)

Implement Comparator interface and override its compare method

b)

It is not possible

c)

Implement Comparator interface and override its compareTo method

d)

Implement Comparator interface and override its comparable method

46.

What does Collections.sort internally uses when number of elements are less than 7?

a)

Insertion sort

b)

Merge sort

c)

Quick sort

d)

None

47.

What does Collections.sort internally uses when number of elements are greater than 7?

a)

Insertion sort

b)

Merge sort

c)

Quick sort

d)

None

48.

Which of the following statements are true with respect to sets as objects of Hashset?

a)

Set is always an ordered group of objects.

b)

Set allows duplicate objects.

c)

Set does not allow duplicate objects.

d)

Set supports iterators.

49.

Which of the following statements are correct in relation to collections in Java?

a)

A collection can have objects of different types in it.

b)

The Collection is a class.

c)

A collection can have only one type of object in it.

d)

A collection is same as a standard array.

50.

Which of the following statements are correct with respect to a Map in Java?

a)

A map can have iterators for accessing its elements.

b)

The elements of a map are accessed by the respective keys.

c)

Maps are the same as a SortedSet.

d)

None of these.

51.

Which of the following interfaces are not a part of the Java's Collection Framework?

a)

SortedList

b)

Set

c)

SortedMap

d)

List

52.

Which of the following statements are correct with respect to a List in Java?

a)

A List is implemented in the "first-in, first-out" (FIFO) order.

b)

A List is implemented in the "first-in, last-out" (FILO) order.

c)

Lists support duplicate items.

d)

None of these.

53.

Which of the following interfaces must contain a unique element?

a)

List

b)

Set

c)

Array

d)

Collection

54.

Which of the following method deletes all the elements from invoking (calling) collections?

a)

reset()

b)

clear()

c)

delete()

d)

refresh()

55.

-Contains no duplicate elements.

-Can contain at most one Null value.

-Elements are not key-value pairs.

-Accessing an element can be almost as fast as performing a similar operation on an array.


Which of these classes provides the specified features?

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

LinkedHashMap

e)

HashMap

56.

Which of the following statement about Set is true?

a)

A HashSet cannot have a null value.

b)

Set allows duplicate values.

c)

Set allows null values but only single occurrence.

d)

Set extends the Java.util.collection interface.

57.

-Entries are organized as key/value pairs.

-Duplicate entries replace old entries.

-Entries are sorted using a Comparator or the Comparable interface.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

SortedSet

e)

SortedMap

58.
a)

{1=C, 2=JavaEE, 4=Python, 3=PHP}

b)

{1=C, 2=JavaSE, 3=Python, 4=PHP}

c)

{1=C, 2=JavaEE, 3=Python, 4=PHP}

d)

{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}

e)

NullPointerException

59.
a)

{null=null, a=null, b=JavaSE, c=PHP, d=Python}

b)

{a=null, b=JavaSE, c=PHP, d=Python}

c)

{b=JavaSE, c=PHP, d=Python}

d)

Compilation Fails

60.
a)

4

b)

5

c)

6

d)

12

61.

-Entries are not organized as key/value pairs.

-Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

None of the above

62.
a)

[Computer, Network, Networks, Programming, Security]

b)

[Computer, Programming, Network, Networks, Programming, Security]

c)

[Computer, Programming, Computer, Networks, Network, Security]

d)

[Computer, Networks, Network, Programming, Security]

63.

List listNames = new ArrayList();

listNames.add("Tom");

listNames.add("Mary");

listNames.add("Peter");


String name2 = (String) listNames.get(1);

System.out.println(name2);

What is the output of the above code

a)

Tom

b)

Mary

c)

Peter

d)

raises Exception

64.

What is Collection in Java?

a)

A group of objects

b)

A group of classes

c)

A group of interfaces

d)

None of the mentioned

65.

Which of these interface is not part of Java’s collection framework?

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

66.

 What will be the output of the  Java program?

a)

{0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

{0, 1, 2, 3, 4}

d)

{0, 0, 0, 3, 4}

67.

Which of these return type of hasNext() method of an iterator?

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

68.

Which of these methods deletes all the elements from invoking collection?

a)

clear();

b)

reset();

c)

delete();

d)

remove();

69.

How many columns does a have if it is created as follows

int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};?

a)

2

b)

4

c)

8

d)

16

70.

What is the index variable for the element at the first row and first column in array

a?

.

a)

a[0][0]

b)

a[1][1]

c)

a[0][1]

d)

a[1][0]

71.

Which of the following statements assigns the letter S to the third row and first column of a two-dimensional array named strGrid (assuming row-major order).

a)

strGrid[0][2] = "S";

b)

strGrid[1][3] = "S";

c)

strGrid[3][1] = "S";

d)

strGrid[2][0] = "S";

72.

How would you get the value 6 out of the following array

int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};?

a)

a[0][3]

b)

a[1][3]

c)

a[0][2]

d)

a[2][0]

73.

Given the following code segment, what is the value of sum after this code executes?

int[][] matrix = { {1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}};

int sum = 0; int col = matrix[0].length - 2; for (int row = 0; row < 4; row++) { sum = sum + matrix[row][col]; }

a)

4

b)

8

c)

9

d)

12

74.

What are the contents of mat after the following code segment has been executed?

int [][] mat = new int [4][3]; for (int row = 0; row < mat.length; row++) { for (int col = 0; col < mat[0].length; col++) { if (row < col) mat[row][col] = 1; else if (row == col) mat[row][col] = 2; else mat[row][col] = 3; } }

a)

{ {2 3 3}, {1 2 3}, {1 1 2}, {1 1 1}}

b)

{ {2 1 1}, {3 2 1}, {3 3 2}, {3 3 3}}

c)

{ {2 1 1 1}, {3 2 1 1}, {3 3 2 1}}

d)

{ {2 3 3 3}, {1 2 3 3}, {1 1 2 3}}

75.

Given the following code segment, what is the value of sum after this code executes?

int[][] m = { {1,1,1,1},{1,2,3,4},{2,2,2,2},{2,4,6,8}}; int sum = 0; for (int k = 0; k < m.length; k++) { sum = sum + m[m.length-1-k][1]; }

A. 4 B. 6 C. 9 D. 10

a)

4

b)

6

c)

9

d)

10

76.

What are the contents of arr after the following code has been executed?

int[][] arr = { {3,2,1},{1,2,3}}; int value = 0; for (int row = 1; row < arr.length; row++) { for (int col = 1; col < arr[0].length; col++) { if (arr[row][col] % 2 == 1) { arr[row][col] = arr[row][col] + 1; } if (arr[row][col] % 2 == 0) { arr[row][col] = arr[row][col] * 2; } } }

a)

{ {6, 4, 2}, {2, 4, 6}}

b)

{ {3, 4, 2}, {2, 4, 8}}

c)

{ {3, 2, 1}, {1, 4, 6}}

d)

{ {3, 2, 1}, {1, 4, 8}}

77.

Analyze the following code:

public class Test {

public static void main(String[] args) {

boolean[][] x = new boolean[3][];

x[0] = new boolean[1]; x[1] = new boolean[2];

x[2] = new boolean[3];

System.out.println("x[2][2] is " + x[2][2]);

}

}

a)

The program has a compile error because new boolean[3][] is wrong.

b)

. The program has a runtime error because x[2][2] is null.

c)

The program runs and displays x[2][2] is false.

d)

The program runs and displays x[2][2] is null.

78.

Suppose a method p has the following heading:

public static int[][] p()

What return statement may be used in p()?

a)

return 1;

b)

return new int[][]{{1, 2, 3}, {2, 4, 5}};

c)

return new int[]{1, 2, 3};

d)

return int[]{1, 2, 3};

79.

Which of the following is FALSE about arrays on Java

a)

A java array is always an object

b)

Length of array can be changed after creation of array

c)

Arrays in Java are always allocated on heap

80.

Predict the output?

public class Main {

public static void main(String args[]) {

int arr[] = {10, 20, 30, 40, 50};

for(int i=0; i < arr.length; i++)

{

System.out.print(" " + arr[i]);

}

}

}

a)

10 20 30 40 50

b)

Compiler Error

c)

10 20 30 40

81.

class Test {

public static void main(String args[]) {

int arr[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

0

0

b)

garbage value

garbage value

c)

Compiler Error

d)

Exception

82.

public class Main {

public static void main(String args[]) {

int arr[][] = new int[4][];

arr[0] = new int[1];

arr[1] = new int[2];

arr[2] = new int[3];

arr[3] = new int[4];

int i, j, k = 0;

for (i = 0; i < 4; i++) {

for (j = 0; j < i + 1; j++) {

arr[i][j] = k;

k++;

}

}

for (i = 0; i < 4; i++) {

for (j = 0; j < i + 1; j++) {

System.out.print(" " + arr[i][j]);

k++;

}

System.out.println();

}

}

}

a)

Compiler Error

b)

0

1 2

3 4 5

6 7 8 9

c)

0

0 0

0 0 0

0 0 0 0

d)

9

7 8

4 5 6

0 1 2 3

83.

Which of the following is the correct way of importing an entire package ‘pkg’?

a)

import pkg.

b)

Import pkg.

c)

import pkg.*

d)

Import pkg.*

84.

Which of the following is/are advantages of packages?

a)

Packages avoid name clashes

b)

Classes, even though they are visible outside their package, can have fields visible to packages only

c)

We can have hidden classes that are used by the packages, but not visible outside.

d)

All of the above

85.

Which of these is a mechanism for naming and visibility control of a class and its content?

a)

Object

b)

Packages

c)

Interfaces

d)

None of the above

86.

Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?

a)

Public

b)

Protected

c)

No Modifier

d)

All of the mentioned

87.

Arrays in Java are dynamically allocated using the . . . . operator.

a)

create

b)

dynamic

c)

arrayList

d)

new

88.

Which of the following statements correctly declares a two-dimensional integer array?

a)

int Matrix[ ] = new int[5,4];

b)

int Matrix[ ]; Matrix = new int[5,4];

c)

int Matrix[ ][ ] = new int[5][4];

d)

int Matrix[ ][ ] = int[5][4];

89.

Which of the following can be operands of arithmetic operators?

a)

Numeric

b)

Boolean

c)

Both Numeric & Characters

d)

Characters

90.

What will be the output of the following Java program?

class Output {

public static void main(String args[]) {

int a = 1;

int b = 2;

int c;

int d;

c = ++b;

d = a++;

c++;

b++;

++a;

System.out.println(a + " " + b + " " + c); }

}

a)

3 2 4

b)

3 2 3

c)

2 3 4

d)

2 4 4

e)

3 4 4

91.

Which of these can be returned by the operator &?

a)

Integer

b)

Boolean

c)

Integer or Boolean

d)

Character

92.

What will be the output of the following Java program?

class comma_operator {

public static void main(String args[]) {

int sum = 0;

for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)

sum += i;

System.out.println(sum); }

}

a)

5

b)

4

c)

6

d)

14

93.

Which of these can not be used for a variable name in Java?

a)

identifier

b)

identifier & keyword

c)

keyword

d)

none of the mentioned

94.

What will be the output of the following Java code?

class operators {

public static void main(String args[]) {

int x = 8;

System.out.println(++x * 3 + " " + x); }

}

a)

24 8

b)

24 9

c)

27 9

d)

27 8

95.

Which of the following is not an operator in Java?

a)

instanceof

b)

sizeof

c)

>>>=

d)

new

96.

What will be the output of the following Java program?

class jump_statments {

public static void main(String args[]) {

int x = 2;

int y = 0;

for ( ; y < 10; ++y) {

if (y % x == 0)

continue;

else if (y == 8)

break;

else

System.out.print(y + " "); }

}

}

a)

1 3 5 7

b)

2 4 6 8

c)

1 3 5 7 9

d)

1 2 3 4 5 6 7 8 9

97.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

a)

while

b)

do-while

c)

for

d)

none of the mentioned

98.

What will be the output of the following Java code?

class Relational_operator {

public static void main(String args[]) {

int var1 = 5;

int var2 = 6;

System.out.print(var1 > var2); }

}

a)

5

b)

6

c)

true

d)

false

99.

Which of these is not a bitwise operator?

a)

&

b)

&=

c)

|=

d)

<=

100.

What is the output of relational operators?

a)

Integer

b)

Boolean

c)

Characters

d)

Double

101.

int len = "jump it!".length();


What is the value of len?

a)

8

b)

7

c)

9

d)

6

e)

This code does not compile.

102.

int x = "quarantine".indexOf("a");


What is the value of x?

a)

4

b)

3

c)

2

d)

This code does not compile.

e)

StringIndexOutOfBoundsException

103.

String s = "whatever".substring(1,4);


What is the value of s?

a)

"hate"

b)

"hat"

c)

"whate"

d)

"what"

e)

StringIndexOutOfBoundsException

104.

String s1 = "hello";

String s2 = new String("hello");

if (s1 == s2) System.out.print("Hey");

else System.out.print("Yo");


What is the output?

a)

Hey

b)

Yo

c)

There is no output.

d)

This code will not compile.

105.

int p = "Go Paw Patrol!".indexOf("p");


What is the value of p?

a)

0

b)

4

c)

3

d)

-1

e)

This code will not compile.

106.

String s = "cool cat".substring(6);


What is the value of s?

a)

"cat"

b)

"at"

c)

"cool c"

d)

This code does not compile.

e)

StringIndexOutOfBoundsException

107.

String s1 = "goat";

String s2 = s1.substring(0,s1.length());

boolean z = s1.equals(s2);


What is the value of z?

a)

true

b)

false

c)

This code will not compile.

d)

StringIndexOutOfBoundsException

108.

String s = "good job".substring(3, 9);


What is the value of s?

a)

"d job"

b)

"od job"

c)

"d jo"

d)

"od jo"

e)

StringIndexOutOfBoundsException

109.

Which code segment should go in the blank so that count is equal to the number of times "whoa" occurs in str?

a)

str.length() -2

b)

str.length() -4

c)

str.length() - 3

d)

str.length() - 1

e)

str.length()

110.

What is the output of the following:

String myWord = "FUN";

String anotherWord = myWord.toLowerCase();

System.out.println(myWord);

a)

fun

b)

Fun

c)

FUN

d)

"fun"

111.

What is the output of the following?

String a = "I will pass the exams.";

String b = " I will pass the exams. ";

if (a.equals(b))

System.out.println("fail");

else

System.out.println(b.substring(9,12));

a)

pass

b)

fail

c)

Compilation Error

d)

I will pass the exams.

112.

What is the output of the following?

String a = "Are you ready kids?";

String b = "Aye! Aye! Captain!";

System.out.println(a.concat(b));

a)

Are you ready kids? Aye! Aye! Captain!

b)

Compilation Error

c)

Are you ready kids?Aye! Aye! Captain!

d)

Aye! Aye! Captain!

113.

What is the output of the following code?

String a = "19";

String b = "75";

System.out.println(a+" "+b);

a)

19 75

b)

94

c)

Compilation Error

d)

1975

114.

What method of class String is used to remove white spaces at the beginning and end of String objects?

a)

remove()

b)

trim()

c)

concat()

d)

Substring()

115.

What does the following print?

System.out.println( "And yet, it moves!".charAt(0) );

a)

A

b)

n

c)

!

d)

The statement is incorrect.

116.

Examine the following fragment:

String world = "World!";

StringBuffer buf = new StringBuffer( "Hello" );


buf.append(' ');

buf.append( world );

How many StringBuffer objects are constructed?

a)

0

b)

1

c)

2

d)

3

117.

Which phrase best describes a String object after it has been constructed?

a)

Changeable

b)

Write Only

c)

Read Only

d)

Inaccessible

118.

After a StringBuffer has been constructed, how many characters may be added to it?

a)

No more after it has been constructed.

b)

Only as many as the original capacity.

c)

As many as needed; it will grow in size if necessary.

d)

A new StringBuffer must be constructed each time characters are added.

119.

What is the potential number of characters in a StringBuffer called?

a)

length

b)

size

c)

width

d)

capacity

120.

What is the current number number of characters in a StringBuffer called?

a)

length

b)

size

c)

width

d)

capacity

121.
Why don't we have to save the result of the append() method of Stringbuffer in a variable?
a)
It changes the Stringbuffer instance on which the method is called on.
b)
There is only one variable of type Stringbuffer, so Java knows where to save the result
c)
Java Magic
122.

What is the output of the following code snippet?

public class Demo{

public static void main(String args[]) {

String s = "String is ";

s.concat("Immutable ");

System.out.println(s+"Immutable");

}

}

a)

String is

b)

String is Immutable

c)

String is Immutable Immutable

d)

String is Immutable String is

123.

The result of the following code


public class Demo

{

public static void main(String args[]){

String str1="Welcome"; //Line-1

String str2=new String(str1); //Line-2

if(str1.equals(str2))

System.out.println("Java");

else

System.out.println("Python");

}

}

a)

Python

b)

Java

c)

Error in Line2

d)

Error in Line1

124.

Identify the result of the following code.

public class Demo{

public static void main(String args[]){

String str = "Student";

System.out.println(str.reverse()); // Line-1

}

}

a)

a) Student

b)

a) tnedutS

c)

a) Error in Line-1

d)

a) Compile Time Error

125.

The output of the following code

public class Demo

{

public static void main(String args[]){

String str = "Java is Life";

//single space between words

StringBuffer sb = new StringBuffer(str);

sb.delete(4,8);

System.out.println(sb);

}

}

a)

Java Life

b)

Javas Life

c)

JavaLife

d)

Java is