New Java Certification Question For You Guys

Today, fyhao gives you another Java Certification Question, see if you can answer it right. More practice before you earn a certification.

Q4

Develop code that implements all forms of loops and iterators, including the use of for, the enhanced for (for-each), do, while, labels, break, and continue; and explain the values taken by loop counter variables during and after loop execution.

2) Given:

5. public class Buddy {

6.   public static void main(String[] args) {

7.     def:

8.     for(short s = 1; s < 7; s++) {

9.       if(s == 5) break def;

10.       if(s == 2) continue;

11.       System.out.print(s + “.”);

12.     }

13.   }

14. }

 

 

What is the result?

a) 1.

 

b) 1.2.

c) 1.3.4. (*)

d) 1.2.3.4.

e) 1.3.4.5.6.

f) 1.2.3.4.5.6.

g) Compilation fails.

Q5

What will happen when you attempt to compile and run the following code?

 

public class Agg{

static public long i=10;

public static void main(String argv[]){

switch(i){

default:

System.out.println(“no value given”);

case 1:

System.out.println(“one”);

case 10:

System.out.println(“ten”);

case 5:

System.out.println(“five”);

}

}

}

 

A. Compile time error

B. Output of “ten” followed by “five”

C. Output of “ten”

D. Compilation and run-time error because of location of default

Is it simple to you?

Read Java Certification Question Q1 to Q3

Author: fyhao

Jebsen & Jessen Comms Singapore INTI University College Bsc (Hon) of Computer Science, Coventry University

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.