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.
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
| 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); | ||||||
| } | |||||||
| } | |||||||
| In no-arg constructor |
| In constructor with an int argument |
| System.out.println("-0.0 == 0.0 returns " + (-0.0 == 0.0)); |
| System.out.println("0.0 > -0.0 returns " + (0.0 > -0.0)); |
___________________________________
| public | class | Temp{ |
| public | static void main(String[] args){ | |
| String[] a = null; | ||
| System.out.println("The length of the array is " + a.length): | ||
| } | ||
| } |
char a;
Which of the following are valid values that can be assigned to a?
| 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); | ||
| } | ||
| } |
In base amethod
In child another
Value of staticInt is 30
Value of instanceVar is 40
In base amethod
In child another
Value of staticInt is 10
Value of instanceVar is 20
In child amethod
In child another
Value of staticInt is 30
Value of instanceVar is 40
| 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); | ||
| } | ||
| } |
| 10 |
| I = 2 j=5 |
| 15 |
| I = 3 j = 5 |
| 5 |
| I = 2 j=5 |
| 15 |
| I = 3 j = 5 |
ANSWERS:-
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.
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.
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.
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.
-0.0 > 0.0 returns false
Check out the Java Language Specification for more information on Character Literal and Escape Sequences
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
Unlike methods, a constructor cannot be abstract, static, final, strictfp, native or synchronized.