This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passed SCJP 1.4 98%

 
Bala Rathakrishnan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Completed my SCJP today. I scored 98%. Missed out a question on Threads. I used Kathy Sierra's book and Kaled A Mugals book. Took 5 mock exams from CD that came along with the books.

Some sample questions

class B {
}
public class A {
private B myB= new B();

void killIt(B b) {
b=null;
}

void doIt() {
killIt(myB);
}

}

Select 2 correct Answers
A. There are no Object eligible for Garbage collection
B. Explicitly setting myB to null will make it eligible for Garbage collection
C. Private instances of B will be eligible for Garbage collection when instances of B are garbage collected
D. 1 Object eligible for Garbage collection

Answer : B & C (had a dilemma whether to choose A or B)


Question 2:
class ThreadImplementer implements Runnable {
public void run() {
System.out.println("Running");
}
public void start() {
System.out.println("Starting");
}
}

public class myThread extends Thread {
public void run() {
System.out.println("Running in my Thread");
}
public static void main(String[] args) {
(new Thread(new ThreadImplementer())).start();
}
}

What will be the output
A. Running in my Thread
B. Starting
C. Running
D. Compilation error
E. RunTime Exception

I selected B. This might be the question where I lost it. I think I reproduced the question to my knowledge.


Question 3
11. void doIt() {
10. A a= new A();
11. B b= new B();
12. b.doSomething(a);
13. a = null;
14. b = null;
15. }

When will the object created at line 10 be eligible for Garbage Collection
A. After line 13
B. After line 14
C. After exiting doIt() method
D. Cannot be determined

Answer. D




Question 4
class myThread extends Thread {
int a;
public void run() {
for (int i=0;i<10;i++) {
if ((i % 2) ==0)
a = 10;
else
a= 5;
}
a=10;
}
}
public class TestIt {
public static void main(String[] args) {
myThread a= new myThread();
a.start();

// Here

System.out.println("int value "+ a.a);
}
}

What should be added at the place //Here to produce the output "int value 10"
A. a.wait();
B. a.run();
C. Thread.sleep(1000);
D. a.join();

Answer : D
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic