Rao Rekha

Greenhorn
+ Follow
since Jul 29, 2002
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 Rao Rekha

That makes complete sense. Thanks Jha and Chitra.
Could anyone kindly let me know why does the following code prints 3 ?
class TestClass
{
public static void main(String args[])
{
boolean b = false;
int i = 1;
do
{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
Thanks in advance.
DAMN !!! such a silly mistake..
Thanks Barkat !!!
Could anyone explain me why the first program is giving an error that the static main method cannot reference non static method showij() and showk(), while a similar second progam compiles and runs just fine !!!
Prg 1 :
--------
class a
{
void showij()
{
System.out.println("i and j");
}
}
class b extends a
{
void showk()
{
System.out.println("k");
}
}

class intest
{
public static void main(String args[])
{
a a1 = new a();
b b1 = new b();
a.showij();
b.showk();
}
}
Prg 2 :
---------
class testty
{
void testt()
{
System.out.println("testt");
}
void testt1()
{
System.out.println("testt1");
}
}
class testy
{
public static void main(String args[])
{
testty t = new testty();
t.testt();
t.testt1();
}
}
Thank you Dan. I didnt know about this instance intializer before. It is only after seeing the questions at your web site that I got the doubt.
Anyway, your website has been very useful this way.
Thanks again.
Could somebody kindly explain to me why a system.out.println("...") statement works without giving any error when specified within a pair of curly braces inside a class like the following.
0
class test{
{
System.out.println("...");
}
}
But it gives an error without the inner curly braces. Why?

Thank you
Thanks for the response Barry. Being new to this Thread concepts, I am not sure about my learning example. But I was expecting it to print "main". Does this mean that, during execution, there will be 2 different threads? Also, I didnt quite get what you said - "sleep() is a class method. So your t.sleep is really calling Thread.sleep(), but in the context of your main thread. So it is your main thread that is sleeping. The thread t that you created has long finished when you do the isAlive() call. " Could you please explain further? Thanks
Hi all,
I have a small learning example here that I wrote to check if a thread is alive after putting it to sleep for 3 secs. But unfortunately the isAlive() method isn't returning true. Why is this thread dead ???

class threads implements Runnable
{
public void run()
{
// do something here..
}
}
class threadtest
{
public static void main(String args[])
{
Runnable r = new threads();
Thread t = new Thread(r);
t.start();
try{
t.sleep(3000);
}
catch(InterruptedException e)
{}


if(t.isAlive())
System.out.println("This is in a thread " + Thread.currentThread().getName());
}
}

Originally posted by Veena Point:
1 int i=0;
2 i=i++;
3 i=i++;
4 i=i++;
It is not clear to me how i is 0 .In line 2 first i is assigned 0 then it is incremented.In line 3 incremented value of i should be assigned ,right?
That is in line 3 1 is assigned to i & then again it gets incremented to 2.
Veena



Because, the first time it assigns zero to i and then increments the value of i on the right, which is immaterial, because, it has already been assigned.

So, in the second step, i retains the value that was initially assigned, which is 0.
Thanks Valentin.
I have tried that but no use. It just isn't recognizing my class1 either in class2 nor class3(where I am trying to create an instance of class1). It gives the error -
cannot resolve symbol
symbol : class class1
location: class p1.class1 ....
I have 3 classes class1, class2 and class3 in the package p1. class2 extends class1. All these classes contain package statement(not using import statement anywhere). In such a case, where do I place the class2 in my directory structure? If I place it inside the folder p1, compiler gives "file not found error" because it extends class1. But if I place it outside p1 folder, it compiles fine. But shouldn't I place a class in a folder named same as the package if there is a package statement specified? Could anyone clear my doubt. Thanks