InfyTQ Arrays and String Quiz 3

Question 1

Time: 00:00:00
Examine the following program fragment:

 

  int[] array = { 1, 4, 3, 6 };

  int what    = 0;

 

  // scan the array

  for ( int index=0; index < array.length; index++ )

  { 

      what = what + array[ index ] ;  

  }

  System.out.println( what );

14

14

1

1

6

6

1 4 3 6

1 4 3 6

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
  What will be the output of below statements?

String s = "Java"+1+2+"Quiz"+""+(3+4); System.out.println(s);

Java3Quiz7

Java3Quiz7

Java12Quiz7

Java12Quiz7

Java12Quiz34

Java12Quiz34

Java3Quiz34

Java3Quiz34

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
 Fill in the blank in the following code fragment so that each element of the array is assigned twice the value of its index.

 

  int[] array = new int[10];

 

  // scan the array

  for ( int index=0; index < array.length; index++ )

  { 

     _______________________ 

  }

index = 2*index;

index = 2*index;

array[ 2*index ] = 2*index;

array[ 2*index ] = 2*index;

array[ index ] = 2*array[ index ];

array[ index ] = 2*array[ index ];

array[ index ] = 2*index;

array[ index ] = 2*index;

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Which of the following is a final class in Java?

String.

String.

StringBuffer.

StringBuffer.

StringBuilder.

StringBuilder.

All of these

All of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
Is it possible to use String in the switch statement?

No, it's not.

No, it's not.

None of these.

None of these.

Yes, it is supported from JDK version 6 onward.

Yes, it is supported from JDK version 6 onward.

Yes, it is supported from JDK version 7 onward.

Yes, it is supported from JDK version 7 onward.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
What is the value displayed by the expression Java.length()?

String Java = "Are you a Java expert? Yes, you are.";

37

37

36

36

34

34

30

30

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
Which of the following statement mentions the right ways to concatenate the two strings?

 None of these.

 None of these.

Str1.append(Str2) and Str1 + Str2.

Str1.append(Str2) and Str1 + Str2.

Str1.substring(Str2) and Str1 && Str2.

Str1.substring(Str2) and Str1 && Str2.

Str1.concat(Str2) and Str1 + Str2.

Str1.concat(Str2) and Str1 + Str2.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
Why Char array is preferred over String for storing password?

String is immutable in java while char array is not that would avoid unauthorized changes to password.

String is immutable in java while char array is not that would avoid unauthorized changes to password.

Strings are cached and available in memory for longer duration while char array can be set to blank once we are done with it.

Strings are cached and available in memory for longer duration while char array can be set to blank once we are done with it.

Java automatically does autoboxing for a char i.e why the char array is preferable over the String.

Java automatically does autoboxing for a char i.e why the char array is preferable over the String.

none of these

none of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
What is the result of the below lines of code?

String str1 = "How are you?";

String str2 = str1.substring(5, 7);

System.out.println(str2);

ar

ar

are

are

None of these

None of these

Re

Re

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
What is the initial capacity of the string builder in the example given below?

StringBuilder sb = new StringBuilder("top 30 Java String interview questions.");

40

40

39

39

55

55

31

31

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Completed

0/0

Accuracy

0%