Search This Blog

Saturday, August 6, 2011

OCPJP(SCJP1.6) Question 30

   1: import java.io.File;
   2: import java.io.IOException;
   3:  
   4: /**
   5:  * Created by IntelliJ IDEA.
   6:  * User: Owner
   7:  * Date: 8/6/11
   8:  * Time: 12:57 PM 
   9:  */
  10: public class TestCreateNewFile {
  11:     public static void main(String[] args) throws IOException {
  12:         File f = new File("scjp6exam.txt");
  13:         System.out.println(f.exists());
  14:         f.createNewFile();
  15:         System.out.println(f.exists());
  16:     }
  17: }

Options :

A. Prints “ false, false”.

B. Prints “ false, true”

C. Can throw an exception at Line 14.

D. Line 15 may not be executed.

OCPJP(SCJP1.6) Question 30SocialTwist Tell-a-Friend

OCPJP(SCJP 1.6) Question 29

   1: public class StringInstanceOfTest {
   2:     public static void main(String[] args) {
   3:         String s = null;
   4:         if(s instanceof String){
   5:             System.out.println("s is instance of String");
   6:         }
   7:         else{
   8:             System.out.println("s is not an instance of String");
   9:         }
  10:     }
  11: }

Output :


A. Compilation fails.


B. Throws Exception at line 4.


C. Prints “s is instance of String”.


D. Prints “s is not an instance of String”.


OCPJP(SCJP 1.6) Question 29SocialTwist Tell-a-Friend