JavaBeat
Search JavaBeat

Certification Kits
SCJP 1.5 Exam Questions
SCJP 1.6 Exam Questions
SCWCD 1.4 Exam Questions
SCWCD 5.0 Exam Questions
SCBCD 5.0 Exam Questions
SCJP 1.5 Links
scjp 1.4 home
scjp books
scwcd Books
objectives
mock exams
scjp 1.4 mock - 1
scjp 1.4 mock - 2
scjp 1.4 mock - 3
scjp 1.4 mock - 4
scjp 1.4 mock - 5
scjp 1.4 mock - 6
scjp 1.4 mock - 7
scjp 1.4 mock - 8
scjp 1.4 mock - 9
scjp 1.4 mock - 10
scjp 1.4 mock - 11
scjp 1.4 mock - 12
scjp 1.4 mock - 13
scjp 1.4 mock - 14
scjp 1.4 mock - 15
scjp 1.4 mock - 16
scjp 1.4 mock - 17
scjp 1.4 mock - 18
scjp 1.4 mock - 19
scjp 1.4 mock - 20
scjp 1.4 mock - 21
newbie
prometric center
Certification Links
SCJP 1.4
SCJP 1.5
SCJP 1.6
SCWCD 1.4
SCWCD 5.0
SCBCD 5.0
SCEA
SCEA 5.0
JavaBeat
Home
Articles
Tips
Code
QnA
Forums
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details

1.What is the result when you compile and run the following code?

class Top {

   static void myTop() {
      System.out.println("Testing myTop method in Top class");
   }
}
public class Down extends Top {

    void myTop() {
          System.out.println("Testing myTop method in Down class");
    }
    public static void main(String [] args) {
        Top t = new Down();
         t.myTop();
    }
}

A) Compile Time error
B) Runtime error
C) Prints Testing myTop method in Top class on the console
D) Prints Testing myTop method in Down class on the screen

2. Which of the code fragments will throw an "ArrayOutOfBoundsException" ?

A) for (int i = 0; i < args.length; i ++ ) {
           System.out.print( i ) ;
     }
B) System.out.print(args.length);
C) for ( int i = 0; i < 1; i++ ) {
          System.out.print(args[i]);
     }
D) None of the above

3. What is the result of the following program, when you compile and run?

public class MyTest {

     final int x;
     public MyTest() {
         System.out.println( x + 10 );
     }
     public static void main( String args[] ) {
            MyTest mt = new MyTest();
     }
}

A) Compile time error
B) Runtime error
C) Prints on the screen 10
D) Throws an exception

4. What is the output when you compile and run the following code fragment?

class MyTest {

   public void myTest() {
         System.out.println("Printing myTest in MyTest class");
   }

   public static void myStat() {
         System.out.println("Printing myStat in MyTest class");
   }
}

public class Test extends MyTest {

    public void myTest() {
         System.out.println("Printing myTest in Test class");
   }

   public static void myStat() {
         System.out.println("Printing myStat in Test class");
   }

   public static void main ( String args[] ) {

       MyTest mt = new Test();
       mt.myTest();
       mt.myStat();
   }

A) Printing myTest in MyTest class followed by Printing myStat in MyTest class
B) Printing myTest in Test class followed by Printing myStat in MyTest class
C) Printing myTest in MyTest class followed by Printing myStat in MyTest class
D) Printing myStat in MyTest class followed by Printing myStat in MyTest class

5. Select all  the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally?

class T implements Runnable {

       public void run() {
               System.out.println( "Executing run() method" );
               myTest();
       }

      public synchronized void myTest() {
               try {
                   wait(-1000); 
                   System.out.println( "Executing the myTest() method" ) ;
               }   XXX
       }
}

public class MyTest {

       public static void main ( String args[] ) {
               T t = new T();
               Thread th = new Thread ( t );
                th.start();
       }
}

A) catch ( InterruptedException ie) {}
B) catch ( IllegalArgumentException il ) {}
C) catch ( IllegalMonitorStateException im ) {}
D) Only catch ( InterruptedException e ) {} exception

6. Which of the following are examples of immutable classes , select all correct answer(s)?

A) String
B) StringBuffer
C) Double
D) Integer

7. Select the correct answer for the code fragment given below?

public class TestBuffer {

     public void myBuf( StringBuffer s, StringBuffer s1) {
            s.append(" how are you") ;
            s = s1;
     }

     public static void main ( String args[] ) {
             TestBuffer tb = new TestBuffer();
              StringBuffer s = new StringBuffer("Hello");
              StringBuffer s1 = new StringBuffer("doing");
              tb.myBuf(s, s1);
              System.out.print(s);
      }
}

A) Prints Hello how are you
B) Prints Hello
C) Prints Hello how are you doing
D) Compile time error

8. What is the result when you compile and run the following code?

public class MyTest {

   public void myTest( int[] increment ) {
          increment[1]++;
   }

   public static void main ( String args[] ) {
         int myArray[] = new int[1]; 
         MyTest mt = new MyTest();
         mt.myTest(myArray);
         System.out.println(myArray[1]);
   }
}

A) Compile time error
B) Runtime error
C) ArrayOutOfBoundsException
D) Prints 1 on the screen 

9. Chose all  valid identifiers?

A) int100
B) byte
C) aString
D) a-Big-Integer
E) Boolean
F) strictfp

10. Select the equivalent answer for the code given below?

boolean b = true;
if ( b ) {
    x =  y;
} else {
   x = z;
}

A) x = b ? x = y : x = z ;
B) x = b ? y : z ;
C) b = x ? y : z ;
D) b = x ? x = y : x = z ;

11. Chose all correct answers?

A) int a [][] = new int [20][20];
B) int [] a [] = new int [20][];
C) int [][] a = new int [10][];
D) int [][] a = new int [][10];

12. Consider the following code and select the correct answer?

class Vehicle {

     String str ;
     public Vehicle() {
     }
     public Vehicle ( String s ) {
     str = s;
     }
}

public class Car extends Vehicle {

      public static void main (String args[] ) {
             final Vehicle v = new Vehicle ( " Hello" );
             v =  new Vehicle ( " How are you");
             v.str = "How is going";
     System.out.println( "Greeting is : "  + v.str );
     }
}

A) Compiler error while subclassing the Vehicle
B) Compiler error , you cannot assign a value to  final variable
B) Prints Hello
C) Prints How is going

13. Java source files are concerned  which of the following are true ?

A) Java source files can have more than one package statements.
B) Contains any number of non-public classes and only one public class
C) Contains any number of non-public classes and any number of public classes
D) import statements can appear anywhere in the class
E) Package statements should appear only in the first line or before any import statements of source file 

14. Select all correct answers from the following?

int a = -1;
int b = -1;
a  = a >>> 31;
b = b >> 31;

A) a = 1, b =1
B) a = -1, b -1
C) a = 1, b = 0
D) a = 1, b = -1

15. What is the value of  a , when you compile and run the following code?

public class MyTest {

         public static void main ( String args[] ) {

int a = 10;
int b = 9;
int c = 7;
a = a ^ b ^ c;
System.out.println ( a );

}

}

A) 10
B) 9
C) 7
D) 4

16. The following code has some errors, select all the correct answers from the following?

public class MyTest {

         public void myTest( int i ) {
                 for ( int x = 0; x < i; x++ ) {
                       System.out.println( x ) ;
                 }
          }
          public abstract void Test() {
                  myTest(10);
          }
}

A) At class declaration
B) myTest() method declaration
C) Test() method declaration
D) No errors, compiles successfully

17. At what point the following code shows compile time error?

class A {
         A() {
              System.out.println("Class A constructor");
          }
}

class B extends A {
         B() {
              System.out.println("Class B constructor");
          }
}

public class C extends A {
         C() {
              System.out.println("Class C constructor");
          }

         public static void main ( String args[] ) {
                 A a = new A(); // Line 1
                 A a1 = new B(); // Line 2
                 A a2 = new C(); // Line 3
                 B b = new C(); // Line 4
          }
}

A) A a = new A(); // Line 1
B) A a1 = new B(); // Line 2
C) A a2 = new C(); // Line 3
D) B b = new C(); // Line 4

18. Which of the following statements would  return false? if given the following statements.

String s = new String ("New year");
String s1 = new String("new Year");

A) s == s1
B) s.equals(s1);
C) s = s1;
D) None of the above

19. Select all correct answers about what is the definition of an interface?

A) It is a blue print 
B) A new data type
C) Nothing but a class definition
D) To provide multiple inheritance

20. Select all correct answers from the following code snippets?

A) // Comments
     import java.awt.*;
     package com;

B) import java.awt.*;
    // Comments
     package com;

C) package com;
     import java.awt.*;
     // Comments

D)  // Comments
      package com;
      import java.awt.*;
      public class MyTest {}

21. What is the result when you compile and run the following code?

public class MyError {

       public static void main ( String args[] ) {
              int x = 0;
              for ( int i = 0; i < 10; i++ ) {
                     x = new Math( i );
                    new System.out.println( x );
              }
        }
}

A) Prints 0 to 9  in sequence
B) No output
C) Runtime error
D) Compile time error

22. There are two computers are connected to internet, one computer is trying to open a socket connection to read the home page of another computer, what are the possible exceptions thrown while connection and reading InputStream?.

A) IOException
B) MalformedURLException
C) NetworkException
D) ConnectException

23. What is the result from the following code when you run?

import java.io.*;

class A {

         A() throws Exception {
                System.out.println ("Executing class A constructor");
                throw new IOException();
          }
}

public class B extends A {
          B() {
                System.out.println ("Executing class B constructor");
           }

           public static void main ( String args[] ) {
                   try {
                   A a = new B();
                   } catch ( Exception e) {
                               System.out.println( e.getMessage() );
                   }
           }
}

A) Executing class A constructor
B) Executing class B constructor
C) Runtime error
D) Compile time error

24. What is the result from the following code when you run?

import java.io.*;

class A {

         A()  {
                System.out.println ("Executing class A constructor"); 
          }
        A(int a) throws Exception {
                 System.out.println ("Executing class A constructor");
                  throw new IOException();
         }

}

public class B extends A {
          B() {
                System.out.println ("Executing class B constructor");
           }

           public static void main ( String args[] ) {
                   try {
                   A a = new B();
                   } catch ( Exception e) {
                               System.out.println( e.getMessage() );
                   }
           }
}

A) Executing class A constructor followed by Executing class B constructor
B) No output
C) Runtime error
D) Compile time error

25. What is the result when you compile and run the following code?

byte Byte = 10;
byte Double = 12;
byte Integer = Byte * Double;

A) 120;
B) Compile time error while declaring variables
C) Compile time error while multiplication
D) None of the above

26. Select all valid methods for Component class?

A) setBounds(), setVisible(), setFont()
B) add(), remove()
C) setEnabled(), setVisible()
D)addComponent()

27. Which subclasses of the Component class  will display the MenuBar?

A) Window, Applet
B) Applet, Panel
C) Frame
D) Menu, Dialog

28. Select all correct answers from the following statements? 

A) Frame's default layout manager is BorderLayout
B) CheckBox, List are examples of non visual components
C) Applets are used to draw custom drawings
D) Canvas has no default behavior or appearance

29. Select all the methods of java.awt.List?

A) void addItem(String s), int getRows()
B) void addItem(String s, int index), void getRows()
C) int[] getSelectedIndexes(), int getItemCount()
D) int[] getSelectedIndexes(), String[] getSelectedItems()

30. Please select all correct answers?

A) java.awt.TextArea.SCROLLBARS_NONE
B) java.awt.TextArea does not generate Key events 
C) java.awt.TextField generates Key events and Action events
D) java.awt.TextArea can be scrolled using  the  <-- and --> keys.

31. What is the result if you try to compile and run the following code ? 

public class MyTest { 

   public static void myTest() {
          System.out.println( "Printing myTest() method" ); 
   }
   public void myMethod() { 
         System.out.println( "Printing myMethod() method" ); 

   } 
   public static void main(String[] args) {
          myTest();
          myMethod(); 
   }

}

A) Compile time error
B) Compiles successfully 
C) Error in main method declaration
D) Prints on the screen Printing myTest() method followed by Printing myMethod() method

32. What line of a given program will throw FileNotFoundException?

import java.io.*;

public class MyReader {

        public static void main ( String args[] ) {
                try {
                         FileReader fileReader = new FileReader("MyFile.java");
                         BufferedReader bufferedReader = new BufferedReader(fileReader);
                         String strString; 
                         fileReader.close();

                while ( ( strString = bufferedReader.readLine()) != null ) {
                          System.out.println ( strString );
                }

       } catch ( IOException ie) { 
                 System.out.println ( ie.getMessage() );
         }

        }
}

A) This program never throws FileNotFoundException
B) The line fileReader.close() throws FileNotFoundException
C) At instantiation  of FileReader object.
D) While constructing the BufferedReader object

33. When the following  program will throw an IOException?

import java.io.*;

class FileWrite {
       public static void main(String args[]) {
              try {
              String strString = "Now is the time to take Sun Certification";
              char buffer[] = new char[strString.length()];
              strString.getChars(0, strString.length(), buffer, 0); 
              FileWriter f = new FileWriter("MyFile1.txt");
              FileWriter f1 = f;
              f1.close();
              for (int i=0; i < buffer.length; i += 2) {
                   f.write(buffer[i]);
              }
             f.close();

            FileWriter f2 = new FileWriter("MyFile2.txt");
            f2.write(buffer);
            f2.close();
            } catch ( IOException ie ) {
                System.out.println( ie.getMessage());
            }
      }
}

A) This program never throws IOException
B) The line f1.close() throws IOException
C) While writing to the stream f.write(buffer[i]) throws an IOExcpetion
D) While constructing the FileWriter object 

34. Which line of the program could be throwing an exception, if the program is as listed below. Assume that "MyFile2.txt" is a read only file.
 

Note: MyFile2.txt is read only file..

import java.io.*;

class FileWrite {
       public static void main(String args[]) {
              try {
              String strString = "Updating the critical data section"
              char buffer[] = new char[strString.length()];
              strString.getChars(0, strString.length(), buffer, 0); 
              FileWriter f = new FileWriter("MyFile1.txt");
              FileWriter f1 = f; 
              for (int i=0; i < buffer.length; i += 2) {
                   f1.write(buffer[i]);
              }
             f1.close();

              FileWriter f2 = new FileWriter("MyFile2.txt");
              f2.write(buffer);
              f2.close();
            } catch ( IOException ie ) {
                System.out.println( ie.getMessage());
            }
      }
}

A) This program never throws IOException
B) The line f1.close() throws IOException
C) While writing to the stream f1.write(buffer[i]) throws an IOException
D) While constructing the FileWriter f2 = new FileWriter("MyFile2.txt");

35. Select all the correct answers about File Class? 

A) A File class can be used to create files and directories
B) A File class has a method mkdir() to create directories
C) A File class has a method mkdirs() to create directory and its parent directories
D) A File cannot be used to create directories

36. Using File class, you can navigate the different directories and list all the files in the those directories?

A) True
B) False

37. Select all the constructor definitions of  "FileOutputStream"?

A) FileOutputStream(FileDescriptor fd)
B) FileOutputStream(String fileName, boolean append)
C) FileOutputStream(RandomAccessFile raFile)
D) FileOutputStream( String dirName, String filename)

38. Select all correct answers for Font class?

A) new Font ( Font.BOLD, 18, 16)
B) new Font ( Font.SERIF, 24, 18)
C) new Font ( "Serif", Font.PLAIN, 24);
D) new Font ( "SanSerif", Font.ITALIC, 24);
E) new Font ( "SanSerif", Font.BOLD+Font.ITALIC, 24);

39. In an applet programing the requirement is that , what ever the changes you do in the applets graphics context need to be accumulated to the previous drawn information. Select all the correct code snippets?

A) public void update ( Graphics g) {
          paint( g) ;
     }

B) public void update ( Graphics g) {
           update( g) ;
     }

C) public void update ( Graphics g) {
           repaint( g) ;
     }

D) public void update ( Graphics g) {
           print( g) ;
     }

40. How can you load the image from the same server where you are loading the applet, select the correct answer form the following?

A) public void init() {
            Image i = getImage ( getDocumentBase(), "Logo.jpeg");
     }

B) public void init() {
            Image i = getImage ( "Logo.jpeg");
     }

C) public void init() {
            Image i = new Image ( "Logo.jpeg");
     }

D) public void init() {
            Image i = getImage ( new Image( "Logo.jpeg") );
     }

41. Which of the following answers can be legally placed in the place of  XXX?

class Check {
        Check() {  }
}

public class ICheck extends Check {
   public static void main ( String[] args) {
         Object o = new ICheck();
         Check i = new ICheck(); 
         Check c = new Check();

         if ( o instanceof  XXX) {
             System.out.println("True");
      } 
   }

}

A) Object, ICheck only
B) Check , ICheck only
C) Object only
D) Object, Check, ICheck

42. There are 20 threads are waiting in the waiting pool with same priority,  how can you invoke 15th thread from the waiting pool?.

A) By calling resume() method
B) By calling interrupt() method
C) Calling call() method
D) By calling notify(15) method on the thread instance
E) None of the above

43. Select all the correct answers regarding thread synchronization ?