Usha Vydyanathan

Greenhorn
+ Follow
since Jan 03, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Usha Vydyanathan

Hi,
The priority of a Newly created Thread can be changed by the method � public final void setPriority(int newPriority) �. True/False?
answer was False.
I thought it was true.
Eventhough newly created thread has priority same as that of the thread that created it, you can change the priority later.
Can anyone explain why it is false?

Thanks,
Usha
Hi,
Check following code.
class test
{
public static void main(String [] args) {
System.out.println(Math.sqrt(-0));
System.out.println(Math.sqrt(+0));
System.out.println(Math.sqrt(-0.0));
System.out.println(Math.sqrt(+0.0));
}
}
prints
0.0,
0.0
-0.0
0.0
Why Math.sqrt(-0) differs from Math.sqrt(-0.0)?
Thanks,
Usha
Hi,
I got it. There is no problem in the extends clause. When the subclass ctor invokes superclass ctor you must specify the containing instance.
class test extends outer.inner
{
tesr(outer o)
{
o.super();
}
}
this works fine.
Thanks,
Usha
Hi,
I am getting compilation error, when trying to extend a top-level class from a member class.

class outer
{
class inner
{
}
}
class test extends outer.inner
{
}
Is this the right way to do it? Thanks in advance.
regards,
Usha
Hi,
I was trying to throw an exception from an instance initializer block. I added this exception type to the throws clause of the ctor and added try,catch block where and instantiate this class. I am getting compilation error "Exception must be caught or thrown" and "Initializer does not end normally".
Can anyone explain how will I be able to throw an exception from an instance initializer.
Thanks in advance.
Usha
Hi shailesh,
I was getting warning during compilation. After that I was
able to the program.
Usha
Hi,
I thought if a statement is unreachable Java always gives error.
Following code compiles fine eventhough "System.out.println("After stop method");" is not reachable because thread will stop before that.

public class Q1 extends Thread
{
public void run()
{
System.out.println("Before start method");
this.stop();
System.out.println("After stop method");
}

public static void main(String[] args)
{
Q1 a = new Q1();
a.start();
}
}
Can any one explain? Thanks in advance.
regards,
Usha
Hi,
Method signature should include throws clause.
static void throwMethod() throws IllegalAccessException
{}
Usha

Hi,
First case you are creating two strings a,b with same value. First string "hi" will be created and 'a' will hold its reference and second time when you are creating string 'b' with the same value it just return reference of string "hi". Both a and b are referring to the same object.
Second case substring(0,2) method creates new string object that is why a==b will return false.
regards,
Usha
Hi,
I was just trying to find out what kind of errors I will get if I am assiging CR or LF unicode to a character literal. But, When I try to comment it I am getting this message "Unclosed Character Literal" ( I am using // comment if I use /* */ it compiles). Can anyone explain?
//char a='\u000a';
//char a='\u000d';
regards,
Usha
True or False?
Unsigned Right Shift on a Negative Integer always returns
a Positive Integer.
I thought it was true. Answer was False. Why?
Regards,
Usha
Hi,
This problem is from Jtips mock exam # 1. Answer for this is 4.

public class Superclass {
public static void main(String[] args) {
System.out.println(new Subclass().methodA());
}

Superclass() {
System.out.println("SuperClass Constructor Executed");
}

private int methodB() {
System.out.println("methodB in Superclass");
return 9;
}

int methodA() {
System.out.println("methodA in Superclass");
return methodB();
}
}

class Subclass extends Superclass {
Subclass() {
System.out.println("SubClass Constructor Executed");
}

protected int methodB() {
System.out.println("methodB in Subclass");
return 1;
}
}
What is the result ?
1.Prints
a.SubClass Constructor Executed
b.methodA in Superclass
c.methodB in Superclass
d. 1
2.Prints
a.SubClass Constructor Executed
b.SuperClass Constructor Executed
b.methodA in Superclass
c.methodB in Superclass
d. 1
3. Prints
a.SuperClass Constructor Executed
b.SubClass Constructor Executed
b.methodA in Superclass
c.methodB in Subclass
d. 1
4.Prints
a.SuperClass Constructor Executed
b.SubClass Constructor Executed
b.methodA in Superclass
c.methodB in Superclass
d. 9
5.Compile-time error occurs.
It is calling methodB() of superclass and prints 9.
If I remove private modifier or override methodA() in Subclass it calls methodB() of Subclass and prints 1.
Can any one explain.
Regards,
Usha
Hi,
consider this code.
class A
{
A(){System.out.println("In A's Default ctor"} //default ctor
A(int i){System.out.println("Value passed " + i} // Ctor with args
}
class B extends A
{
static int i=5;
B()
{
this(5);
}
B(int i){System.out.println("Value passed " + i)}
}
When I compile and run this code ctor of the base class is being called before calling ctor with argument of the derived class.
My doubt is how compiler is able to insert super() statement even though this(5) is present in the first line of the ctor. I am not able insert both super(arg) and this() in the same ctor because both of them have to be in the first line. Any idea?
regards,
Usha
Hi,
I have been taking few mock exams. I am really confused about
the format of the real exam. For eg. number of answers we have
to choose will be specified or we have to choose all the correct
answers. Format differs from one mock exam to another.
Thanks in advance.
Usha
Hi,
I think instance varibles are initialised in the order they are declared. When variable 'i' is initialised before variable 'j'.

Following code will result in 10.
private int j=10;
private int i=givemeJ();
Correct me if I am wrong.
regards,
Usha