This test has 15 free questions and 110 paid questions.Click here to Add To Cart.

Questions of Test: SCJP 6 Mock Practice Test

More >>

1

Identify the code fragments that execute the method tutor() in a separate thread

2

What would be the output of the following
 
 public static void main(String[] args) {
  long i = (long)Math.round(Math.random());  
  switch(i){
  case 0: System.out.println(0);break;
  case 1:System.out.println(1);break;
  } 
 }

3

public class If {
 
 public static void main(String[] args) {
  
  int i;
  
  if(i=0){
   System.out.println("true");
  }
 }
}
What is the compilation error we get when we compile the above code?

4

What would be the output of following code?

1.  public static void main(String[] args) {
2.     List<Float> list = new ArrayList<Float>();
3.    
4.     list.add(3.1);
5.     list.add(2.09);
6.     list.add(1.0);
7.    
8.     for(Float i : shuffle(list)){
9.         System.out.println(i);
10.     }
11.    
12. }
13. private static<T extends Comparable<? super T>> List<T> shuffle(List<T > list) {
14.     Collections.sort(list);
15.     return list;
16. }

5

What will be the output when the following code is run?
 1. public class Exception {
 2.
 3.  public static void main(String[] args) {
 4.
 5.   try {
 6.    
 7.    List<String> numbers = new LinkedList<String>();  
 8.
 9.    int i = 0;
10.
11.    numbers.add(i + "");
12.
13.    for (; i <5;)
14.     numbers.add(numbers.get(numbers.size() - 1) + i);
15.     i++;
16.    
17.    System.out.printf("Zero - Five %s", numbers);
18.
19.   } catch (Throwable t) {
20.    t.printStackTrace();
21.   }
22.  }
23. }

6

public class Exceptional {
	static int[] i;
	static { i[0]=11; }
	   public static void main(String[] args) { /* main code here */ }
}
What happens when we run the above code?

7

What will be the o/p of the following code:

1. public enum TestEnumDefintion implements Serializable, Runnable {
 2.  
 3.  TEST_I, TEST_II, ;
 4.
 5.  public void run() {
 6.  
 7.   try {
 8.    Thread.sleep(1000);
 9.   } catch (InterruptedException e) {
10.    e.printStackTrace();
11.   }
12.   System.out.println("Running inside an enum!!!");
13.  }
14.  
15.  public static void main(String[] args) {
16.   new Thread(TestEnumDefintion.TEST_I).start();
17.  }
18.
19. }

8

The following piece of code causes a compilation error. Identify the line in which it occurs, and the reason for the error.
1. class Mammal{
2.      void feedMilk()throws Exception {throw new Exception();}
3. }
4. class Bat extends Mammal {
5.      void feedMilk(){ System.out.println("Bat"); }
6. }
7. public class MyMain{
8.      public static void main(String[] args){
9.              Mammal mammal = new Bat();
10.             mammal.feedMilk();
11.     }
12. }

9

Which of the following code fragments might not cause StackOverFlowError?

10

public class SysProp {        
        public static void main(String[] args){         
                String sysProperty = System.getProperty("prop");
                System.out.println(sysProperty);        
}
}
What is the command with the system property option to run the above code producing the output: "scjp"?

More >>
Add To Cart