sampath garapati

Ranch Hand
+ Follow
since Sep 26, 2005
Merit badge: grant badges
For More
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 sampath garapati

class Th extends Thread{
public void run(){System.out.println("ABC");}
public static void main(String[] args) throws Exception
{Th th = new Th();Thread t = new Thread(th)\\1;
t.start();t.join();t.run();}}
---------------------------------------------------------------------------


In this case...
'th' is the reference variable to the object belonging to the class 'Th'. Hence you can say "th.run()" to invoke run() just like anyother method (Note: Only th.start() will create a live thread). But you cannot say "t.run()" because, 't' is the reference to the Thread created and NOT TO THE object of the class 'Th'. So you cannot invoke a method in 'Th' using 't'.


Then why if we execute the following code:

class Th extends Thread{
public void run(){
System.out.println("ABC");
}
public static void main(String[] args) throws Exception{
Th th = new Th();
Thread t = new Thread(th);//1;
t.start();
t.run();
}
}

It is displaying ABC ABC

Please explain

Thanks
Sampath
Ok, you are right. Then how come the answer is 10.
Please explain


Thanks
Sampath
public void method{
for(int i=0;i<=10;i++){
String tmp=Integer.toString(i);//Here when the loop increments the previously assigned value is eligble for GC because the new value is assigned now. When i=11 the loop will exits without executing the loop statements so the 11th (i=10) value is not eligible for GC.
System.out.println(tmp);
}
}


Anything wrong please correct me.

Thanks
Sampath
Congratulations

wish you all the best.

Sampath
18 years ago
Congratulations friend.

All the best for your future exams

Sampath
18 years ago
Go it. Thank You.

Sampath
After what line will the object referenced by i become eligible for garbage collection in the following code?

public class Pannel{
public static void main(String argv[]){
Pannel p = new Pannel();
p.go();
}
public void go(){
Integer i = new Integer(10);
Integer i2 = i;
i = null;
Integer i3 = new Integer(0);
i2= null;

}
}

I think the answer is after the line i = null;
But it is i2 = null;

when i = null is it not eligible for GC.

Please explain

Thanks
Sampath
When will you release the book for SCJP 1.5 of K&B in India.

Sampath
hi Amritha,

The following is an overridden method.

class Bird {
public void print(Bird b){
System.out.println("Bird");
}
}

class Raptor extends Bird {
public void print(Bird b){
System.out.println("Raptor");
}
public static void main(String[] args) {
Bird c = new Raptor();
c.print(new Raptor());
}
}

it prints Raptor. As you said the Super class reference can be used in the Subclass, but not viceversa.

thanks
Sampath
I think that After line 7 the initially referred object by str is eligible for GC. I am not sure.

All of you were said it is after 8.
Please explain.

Sampath
Hai Bates,
I prepared for 1.4 exam. Shall I go for that or wait for one more month and take 1.5
Please give me your suggestion.


Thank You
Sampath
Congrats Naresh


What is the full form of K&B book which u prepare. Where can I get that book.

Sampath
18 years ago
K&B book means , is it "Kathy Sieara & Bert Bates" or something else.
If it is Kathy Sieara & Bert Bates are they releasing book for the SCJP1.5 exam. If so when.

Actually I planned for SCJP1.4 in mid Oct. But if the book releases then I will go for SCJP 1.5.

Can anybody help me on ths.


Sampath
Thank you for your clear explanation. Understood now.

Sampath
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
A a1; B b1;
m(null,null); m(a1=null,b1=null); m(b1, a1);
}}

In the above program why the output is BBABBA, why not AAABBA

please explain

Thank You Sampath