SCJP Tutorial

SCJP Tutorial Print E-mail
Contributed by Howell   
Monday, 05 June 2006

 SCJP Tutorial

This certification is for programmers interested in demonstrating proficiency in the fundamentals of the Java programming language using the Java 2 Platform, Standard Edition (J2SE) technology.

 

SUN CERTIFIED PROGRAMMER FOR THE JAVA 2 PLATFORM

Some questions of scjp


A.  i = 3
B.  Compilation fails.
C.  A ClassCastException is thrown at line 6. D.  A ClassCastException is thrown at line 7.

Which two cause a compiler error? (Choose two)


A.  float[] = new float(3);
B.  float f2[] = new float[]; C.  float[] f1 = new float[3]; D.  float f3[] = new float[3];
E.   float f5[] = { 1.0f, 2.0f, 2.0f };
F.   float f4[] = new float[] { 1.0f. 2.0f. 3.0f};

 

Answer: A, B
The F. statement is incorrect. The float numbers should be separated with commas and not dots.

Given:
11. int i =1,j =10;
12. do {
13. if(i++> --j) {
14. continue;
15. }
16. } while (i <5);
17. System.out.println(“i = “ +i+ “and j = “+j);
What is the result?


A.  i = 6 and j = 5
B.  i = 5 and j = 5
C.  i = 6 and j = 5
D.  i = 5 and j = 6
E.   i = 6 and j = 6

Answer: D

Given:
1. class Test {
2. private Demo d;
3. void start() {
4. d = new Demo();
5. this.takeDemo(d);
6. }
7.
8. void takeDemo(Demo demo) {
9. demo = null;
10. demo = new Demo();
11. }
12. }
When is the Demo object, created on line 3, eligible for garbage collection?

A.  After line 5. B.  After line 9.
C.  After the start() method completes.
D.  When the takeDemo() method completes.
E.   When the instance running this code is made eligible for garbage collection.

Answer: E

 

Given:
1. interface Animal {
2. void soundOff();
3. }
4.
5. class Elephant implements Animal {
6. public void soundOff() {
7. System.out.println(“Trumpet”);
8. }
9. }
10.
11. class Lion implements Animal {
12. public void soundOff() {
13. System.out.println(“Roar”);
14. }
15. }
16.
17. class Alpha1 {
18. static Animal get( String choice ) {
19. if ( choice.equalsIgnoreCase( “meat eater” )) {
20. return new Lion();
21. } else {
22. return new Elephant();
23. }
24. }
25. }
Which compiles?


A.  new Animal().soundOff();
B.  Elephant e = new Alpha1();
C.  Lion 1 = Alpha.get(“meat eater”);
D.  new Alpha1().get(“veggie”).soundOff();

Answer: D

Which statement is true?

A.  Memory is reclaimed by calling Runtime.gc().
B.  Objects are not collected if they are accessible from live threads. C.  Objects that have finalize() methods are never garbage collected.
D.  Objects that have finalize() methods always have their finalize() methods called before the program ends.
E.   An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement.

Answer: B

Given:
1. class A {
2. A() { }
3. }
4.
5. class B extends A {
6. }
Which two statements are true? (Choose two)

A.  Class B’s constructor is public.
B.  Class B’s constructor has no arguments.
C.  Class B’s constructor includes a call to this(). D.  Class B’s constructor includes a call to super().

 

Answer: B, D

Given:
11. int i = 1,j = 10;
12. do {
13. if(i>j) {
14. break;
15. }
16. j--;
17. } while (++i <5);
18. System.out.println(“i =” +i+” and j = “+j);
What is the result?


A.  i = 6 and j = 5
B.  i = 5 and j = 5
C.  i = 6 and j = 4
D.  i = 5 and j = 6
E.   i = 6 and j = 6

 

Answer: D

 

Last Updated ( Friday, 07 July 2006 )

  home              contact us

 

©2006-2012 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground