File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reg a mock exam

 
sundar sankar
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Iam unable to solve the following ques please help me.Iam plamming to tkae scjp5 within a week iam unable to find mock ques related to reg expression.
thanks in advance
sankar
Question 13: There are a number of labels in the source code below. These are labeled a through j. Which label identifies the earliest point where, after that line has executed, the object referred to by the variable first may be garbage collected? class Riddle {
public static void main(String[] args) {
String first, second;
String riddle;
if (args.length < 2)
return; a: first = new String(args[0]);
b: second = new String(args[1]);
c: riddle = "When is a " + first;
d: first = null;
e: riddle += " like a " + second + "?";
f: second = null;
g: System.out.println(riddle);
h: args[0] = null;
i: args[1] = null;
j:
}
}
Select the one right answer.
d:
e:
h:
i:
j:
Question 46: If you supply a target object when you create a new Thread, as in: Thread t = new Thread(targetObject);
What test of instanceof does targetObject have to pass for this to be legal?

Select the one right answer.

targetObject instanceof Thread
targetObject instanceof Object
targetObject instanceof Applet
targetObject instanceof Runnable
targetObject instanceof String

Question 47: What appears in the standard output when you run the Dots class?
class Dots implements Runnable {
DotThread t;
public static void main(String[] args) {
Dots d = new Dots();
d.t = new DotThread();
}
public void init() {
t.start();
t = new DashThread().start();
}
}
class DotThread extends Thread {
public void run() {
for (int index = 0; index < 100; index++)
System.out.print(".");
}
}
class DashThread extends Thread {
public void run() {
for (int index = 0; index < 100; index++)
System.out.print("-");
}
}
nothing
100 dots (.)
200 dots (.)
100 dashes (-)
100 dots (.) and 100 dashes(-)

Question 55: What will happen when you attempt to compile and run the following program by passing the Test class to the Java interpreter? class Test {
public static void main() {
System.out.println("hello");
}
}
Select the one right answer.


The program does not compile because main() is not defined correctly.
The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.
The program compiles but you cannot run it because the class is not declared as public.
The program compiles and runs without an error but does not display anything in the standard output.
The program compiles and displays "hello" in the standard output when you run it.
 
Manfred Klug
Ranch Hand
Posts: 377
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sundar sankar:
Question 13:
Question 47:
Question 55:
What do you think is the correct answer and why?

Question 46:
Have a look at the Thread API documentation.

PS: It is helpful if you make an own thread for each question.
 
R Kumar
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be better if you also mention what you think are the right answers.According to me following are the correct answers. If they are wrong please correct me..

Question 13: h
Question 46: targetObject instanceof Runnable
Question 47: nothing
Question 55: The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.
 
Mohit Jain
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by R Kumar:

Question 13: h


Hi R Kumar

Answer to 'Question 13' is - d: first = null;

have a look - first = new String(args[0]);

since a new object is created (using 'new' operator) and assigned to reference 'first', this object is not referred by any other object in the given code. Therefore, line 'first=null;' makes the object referred by 'first' eligible for garbage collection.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic