Win a copy of Head First Android this week in the Android forum!

shirley tao

Greenhorn
+ Follow
since Sep 07, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by shirley tao

According to my experience, it is included in the requirement in the test.
Please study it clearly as you can.
Good luck!
Shirley
class A extends Thread {
int[] sa1 = new int[3];
public A(int [] sa1) {
this.sa1 = sa1;
}
public void run() {
synchronized (sa1) {
System.out.print(sa1[0] +","+ sa1[1] +","+ sa1[2]);
}
}
}
class B6 {
private static int[] sa = new int[3];
public static void main (String[] args) {

Thread t1 = new A(sa);

t1.start();
synchronized(sa){
sa[0] = 0;
sa[1] = 1;
sa[2] = 2;
}
}
}
Who can explain why the result is 0,1,2?
You are right that the code is trying to access the variable as if it is public. However I also tried if class A & B are in the same package, calling the protected attribute, b.i, is fine.[/QB]
I am a little confused. "i" is a protected variable in A, why can't be accesed from B just because it is not in the same package?
//in file A.java
package p1;
public Class A
{
protected int i=10;
public int getI({return i;}
}
//in file B.java
package p2;
import p1.*;
public class B extends p1.A
{
public void process(A a)
{
a.i=a.i*2;
}
public static void main(String[] args)
{
A a=new B();
B b=new B();
b.process(a);
System.out.println(a.getI());
}
}
What will be the output of compiling and running Class B?
The answer is :
it won't compile.
Who can explain it to me?
Thanks!
But if we change the "run" to "start", what's the difference of the result?
and what's the use of the yield in the code?
Thanks!
Shirley
Anyone have taken the test, could you tell me whether the Daemon thread
appeared in the test? I am not familar with it and I will take the test
tomorrow, so .....?
Or somebody can give me a hand about this?
Thank you very much!
Shirley!

Originally posted by Veena Point:
Even I thought like that.But then again if that is the case why is it printing 01 in between....?
Thanks
Veena


You mean the 0 1 in the printing string. I think that's because it is in the switch block, when j=0 or j=1, it goes to the case "0" or "1" and doesn't execute the sentences in the case default, so assert won't be executed. Am I right?
Shirley

Originally posted by Unni Kainila:
If there is more than one possible correct answers, Sun's exam question will tell you how many correct answers you should select.


That's great!
Thank you very much!

Originally posted by Veena Point:

With assertions enabled the above code prints
210210Exception in thread "main" java.lang.AssertionError
at asert2.m1(asert2.java:12)
at asert2.main(asert2.java:19)
My doubt is shouldn't it print 210210-1 followed by assertion error?
Thanks
Veena


I think the answer is correct. Since when Assert is false, the EXIT method will be called. So the -1 won't be printed. Am I right?
Shirley
Thank you very much! I got it.
Here is the last question.
Does the test tell you how many correct answers for each probelm you should choose?
Thank you in advance!

Originally posted by Arun Subbu:
Hi Shirley,
Once you buy the test from SUN, its valid for one year. You have to check with your local center for the time slot you are planning to take the test.
Buy the test through web, its easy and instant. Once you obtain the promotion/voucher code, you can use prometrics online services to reserve for the test(provided if prometric is your local test center).
All the best.


Thank you very much, Arun. so how long does it take to send me the
voucher code after I buy it from the web?
Shirley
Hi, everyone, I want to take the SCJP 1.4.
I want to know if I buy the test from web today,
when I can take it from the local test center!Is it assigned by the
center or you can choose by yourself?
Thank you very much!!
shirley