Yuki Cho

Ranch Hand
+ Follow
since Apr 18, 2001
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 Yuki Cho

hi Lam,
i think i got it now. It took some time to sink in.
thanks,
yuki
hi there,
can you walk me through this? thanks, yuki
-----------
Given the following code what will be the output?
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20
Answer: 4
hi guys,
thanks for pointing this out. i think i can easily missed this kind of concept. thanx!!!
-yuki
Thanks everybody for replying my question. i got it now. :P
-yuki
The following code prints out 3. I thought it will go in an infinite loop since it is while (true), but it is not. Please explain... thanx!!!
-----------
What will be the result of attempting to compile and run the following program?
class TestClass
{
public static void main(String args[])
{
boolean b = false;
int i = 1;
do
{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
hi there,
can you please explain to me why the following code doesn't compile? i thought class B is able to access class A since B extends A even though they are in different 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());
}
}

thanks,
yuki
hi Lam,
you did an excellent job of walking me through this. your explanation is very clear and thorough. thanks soooooo much!!!
-yuki
so, when extending a thread, we say override the run() method. And for implementing Runnable, we can either say implement run() method or override the run() method. Or both ways can only be overriding the run() method.
thanks,
Yuki
can you please clear this up for me?
For extending thread and implementing runnable, which one implements run and which one overrides run.
thanks,
yuki
hi guys,
please take a look at the following code with these 3 situation?
1. if the code is the way it is, it prints 1, 2, 3, oops.
2.If i changed y to b in line 6, it prints 1,2, oops.
3. If i changed y to b in line 5 and take out the return keyword in line 14, it prints 1,2, oops, oops
Can you explain to me how to approach these 3 situations?
thanks in advance, yuki
---------------
public class Ace{
public static void main(String argv[]){
int b =1;
for(int y =0; y<4; y++){<br /> try {<br /> if(y > 2) { // line 6
throw new Exception();
}
System.out.println(b);
b++;
}
catch (Exception c){
System.out.println("oops");
return; //line 14
}
}
}
}

Thanks Jane, i got it now!
-Yuki
i was wondering why buttons will run from left to right along the top of the frame. I thought the buttons will stay at the button since the layout has been set to the south initially at line 12. Do i need a validate() to apply borderlayout follow by flowlayout? pleaseeeee help.
thanks, yuki
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p); //12
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
you rock Lam. Thanks soooooo much!
-yuki
can somebody walks me through this?
------------
What will be written to the standard output when the following program is run?
class Base {
int i;
Base() {
add(1);
}
void add(int v) {
i += v;
}
void print() {
System.out.println(i);
}
}
class Extension extends Base {
Extension() {
add(2);
}
void add(int v) {
i += v*2;
}
}
public class Qd073 {
public static void main(String args[]) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}
A. 9
B. 18
C. 20
D. 21
E. 22
Answer: E

Thanks,
yuki
it says:
"If a thread is executing method b() on an object, then it is guaranteed that no other thread executes methods a() and b() concurrently. Therefore, the invocation counters i and j will never show more than one concurrent invocation. Two threads can concurrently be executing methods b() and c(). Therefore the invocation counter k can easily show more than one concurrent invocation."