Test Series - java

Test Number 39/64

Q: What is the output of the Java code snippet?
int i=0;
for(i=1; i<=6;i++)
{
  if(i%3==0)
    continue;
  System.out.print(i+",");
}
A. 1,2,
B. 1,2,4,5,
C. 3,6,
D. Compiler error
Solution: CONTINUE statement skips the execution of the remaining statements below it.
Q: The Enhanced FOR loop in Java was introduced by ___.
A. JDK 4
B. JDK 5
C. JDK 6
D. JDK 7
Solution: no solution
Q: An Enhanced FOR loop in Java misses ___ and __ compared to the old-style FOR loop.
A. Speed and Easiness
B. Initialization, Increment/Decrement
C. Semicolons, Variables
D. None
Solution: The condition part is not required as the Enhanced FOR loop iterates through all elements of the Collection from staring to end.
Q: In Java language, BREAK or CONTINUE statements can be implemented inside a Loop only with the help of ___ statements to avoid never-ending loops.
A. IF ELSE
B. SWITCH
C. ENUM
D. None
Solution: no solution
Q: What is the output of the Java program with Enhanced FOR loop below?
String countries[] = {"BRAZIL", "CHILE", "SYDNEY"};
int i=0;
for(String str: countries)
{
  if(i<2)
    ;
  else
    break;
  System.out.print(str + ",");
  i++;
}
A. BRAZIL,CHILE,SYDNEY,
B. BRAZIL,CHILE,
C. BRAZIL,
D. Compiler error
Solution: no solution
Q: What is the output of Java Enhanced FOR loop below?
String names[] = {"MOGLI", "SHAREKHAN", "BALU"};
for(String str: names)
{
  System.out.print(str + ",");
}
A. MOGLI,
B. MOGLI,SHAREKHAN,
C. MOGLI,SHAREKHAN,BALU,
D. Compiler error
Solution: no solution
Q: An enhanced FOR loop work with only Collection type data. Examples of Collection are ___.
A. Array Class type or any regular array variable
B. ArrayList
C. HashMap, HashSet
D. All
Solution: no solution
Q: A BREAK or CONTINUE statement applies only to the ___ loop.
A. Inner loop or the loop containing break or continue
B. always Outer loop
C. Sometimes inner loop, sometimes outer loop
D. None
Solution: no solution
Q: A BREAK-WITH-LABEL or CONTINUE-WITH-LABEL are used in particular in Java to select __ loop either to Break or Continue.
A.  Inner loop
B. Outer loop
C. None
D. blank
Solution: Use the Labels only to choose outer loops. Otherwise, simply use BREAK or CONTINUE without any label.
Q: Choose rules for naming a Label in Java below.
A. The name of a label or identifier may start only with Alphabet, Underscore ( _ ) or Dollar ($) symbol
B. A label is kept before the loop in general
C. Duplicate label names are not allowed
D. All
Solution: no solution

You Have Score    /10