Back to HomePage

Sun Certified Programmer for the Java2 Platform

Mock Exam

This mock exam was created by Chandini Paterson. I�ve put together about 15 questions for this Mock Exam. I am currently working on putting together an applet with more questions, that will be harder and which will have a format similar to the real SCJP exam. However, because of time constraints I haven�t yet been able to. Hopefully it should be ready by the end of May 2001. Please do check back to see if it is ready.

I�ve tried to ensure that there are no wrong answers in my mock exam, but if you find any or would like to otherwise comment on any question/answer, please write to me at [email protected].

Please feel free to link your sites to this page. This page may be distributed freely as long as you don�t modify it in any way, shape or form.

Other Mock Exams: -

Please check out my Top Sites for Java Certification Exam to find some of the best on-line mock exams for the SCJP exam, that are free.

Last Updated on 25th April, 2001


QUESTIONS:-

  1. Which of the following are valid assignment expressions, given the following declarations:-
    byte b;
    int i = 10;
    long l = 20;
    1. b = i;
    2. b += i;
    3. b++;
    4. b = b + i;

    Answer


  2. State true or false: Interface methods can be declared static
    1. true
    2. false

    Answer


  3. Select the correct answers: If you define a class within an interface,
    1. the class is always public
    2. the class is always static
    3. the class methods cannot call methods declared in the interface

    Answer


  4. State true or false: An abstract class can have a constructor
    1. true
    2. false

    Answer


  5. What is the output of the following piece of code:
    class A {
    public A() {
    class B{
    B() {
    System.out.println("In no-arg constructor");
    }
    }
    new B();
    }
    public A(int a) {
    class B{
    B() {
    System.out.println("In constructor with an int argument");
    }
    }
    new B();
    }
    public static void main(String[] args{
    A a1 = new A();
    A a2 = new A(10);
    }
    }
    1. Code does not compile
    2. Code compiles but generates exception at runtime
    3. Code compiles successfully and outputs
      In no-arg constructor
      In constructor with an int argument

    Answer


  6. Select all correct answers: Numeric operators that throw the ArithmeticException on integer operands include
    1. +
    2. -
    3. /
    4. %
    5. *

    Answer


  7. What is the output of the following piece of code.
    System.out.println("-0.0 == 0.0 returns " + (-0.0 == 0.0));
    System.out.println("0.0 > -0.0 returns " + (0.0 > -0.0));

    ___________________________________

    Answer


  8. Select true or false: The equality operator (==) always returns false if either operand is Nan and the inequality operator (!=) return true if either operand is Nan.
    1. true
    2. false

    Answer


  9. Select the correct answers: You can use an instance of a File class to do the following
    1. delete a file
    2. change current working directory
    3. rename files
    4. create new sub-directories

    Answer


  10. What is the output of the following code:
    public class Temp{
    public static void main(String[] args){
    String[] a = null;
    System.out.println("The length of the array is " + a.length):
    }
    }
    1. The code does not compile
    2. The code compiles and prints out "The length of the array is 0";
    3. The code compiles and prints out "The length of the array is null";
    4. The code compiles but generates the NullPointerException at runtime

    Answer


  11. Given the following declaration:

    char a;

    Which of the following are valid values that can be assigned to a?

    1. �\0�
    2. �\u003c�
    3. �\349�
    4. \u004
    5. �\345�

    Answer


  12. Given the following code, what is the output generated
    class Base {
    public static void amethod(){
    System.out.println("In base amethod");
    }
    public void another(){
    System.out.println("In base another");
    }
    static int staticInt = 10;
    int instanceVar = 20;
    }
    public class Child extends Base {
    public static void amethod(){
    System.out.println("In child amethod");
    }
    public void another() {
    System.out.println("In child another");
    }
    static int staticInt = 30;
    int instanceVar = 40;
    public static void main(String[] a ){
    Base b = new Child();
    b.amethod();
    b.another();
    System.out.println("Value of staticInt is = " + b.staticInt);
    System.out.println("Value of instanceVar is = " + b.instanceVar);
    }
    }

    1. Code does not compile
    2. Code compiles and prints out
    3. In base amethod

      In child another

      Value of staticInt is 30

      Value of instanceVar is 40

    4. Code compiles and prints out
    5. In base amethod

      In child another

      Value of staticInt is 10

      Value of instanceVar is 20

    6. Code compiles and prints out
    7. In child amethod

      In child another

      Value of staticInt is 30

      Value of instanceVar is 40

    Answer


  13. Select all correct answers: Modifiers that you CANNOT use with constructors include
    1. private
    2. abstract
    3. static
    4. public
    5. final

    Answer


  14. State true or false: The RandomAccessFile class is compatible with the Stream classes
    1. True
    2. False

    Answer


  15. What is the output of the following piece of code:
    class A{
    public static void main(String[] args){
    int i = 1;
    int j = 5;
    System.out.println((i++ * j));
    System.out.println("i = " + i + " j = "+ j);
    System.out.println((++i * j));
    System.out.println("i = " + i + " j = " + j);
    }
    }
    1. Code does not compile
    2. Code compiles and prints out
    3. 10
      I = 2 j=5
      15
      I = 3 j = 5
    4. Code compiles and prints out
    5. 5
      I = 2 j=5
      15
      I = 3 j = 5

    Answer



    ANSWERS:-

    1. b, c
    2. Remember, that a compound assignment expression of the form E1 op= E2 is always equivalent to E1 = (Type) (E1 op E2), where Type is the type of E1.

    3. b
    4. The only modifiers that are allowed with interface methods are public and abstract. And these are implicit, so you don�t even have to include them.

    5. a,b,c
    6. All three are right. Classes defined within an interface are implicitly public and static and because you cannot have static methods within an iterface, you cannot refer to the non-static methods from the static class methods.

    7. a
    8. c
    9. c, d
    10. The only operators that can cause an ArithmeticException are the integer division (/) and modulo (%) operators. Remember that float operations do not raise any exception at all. They may result in NaN or Infinities, instead.

    11. -0.0 == 0.0 returns true
    12. -0.0 > 0.0 returns false

    13. a
    14. a, c, d
    15. d
    16. a, b, d
    17. Check out the Java Language Specification for more information on Character Literal and Escape Sequences

    18. c
    19. Static variables and methods as well as instance variables use the Type of the reference variable to determine the correct variable/method to use. On the other hand, instance methods use the Class of the reference variable to determine the correct method to call

    20. b,c,e
    21. Unlike methods, a constructor cannot be abstract, static, final, strictfp, native or synchronized.

    22. b
    23. c

    Back to questions




    Back to HomePage


    cover
    The Complete Java 2 Certification Study...



    CopyRight � Chandini Paterson
    Last modified on 31 March, 2009
    Hosted by www.Geocities.ws

    1