Shila Sharma

Greenhorn
+ Follow
since Jul 18, 2002
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 Shila Sharma

Hi All
I have one problem here in the following code.I got this question in a practice test. I think answer is (4) is the correct, sometime (3) also look correct. Can anybody help me in getting the correct one if I am wrong.
class A {}
class B extends A {}
class C extends A implements Runnable { // .. }
class D extends C {}
class E extends C {}
A Aobj=new A();
B Bobj=new B();
C Cobj=new C();
D Dobj=new D();
E Eobj=new E();
Which one of the following cast expressions will fail given the classes defined above?
Ans. 1. (D) Eobj;
2. (A) Eobj;
3. (A) ( (Runnable) Cobj);
4. (A) Bobj;
Thanks
S.
Simple question!
Somebody ( or Val.) Pls tell me about any sites (other tham mock ) for certification preparation where I can get topic-wise questions.
Thanks in advance.
S
Thanks Kyle, for your valuable suggestion
Regards
Shila
Hi Friends
I am new to this forum. One basic question on OO! Today while going thru one topic on OO, I came across this question. I read about polymorphism, but didnot very close (5) answer. Pls let me know, if you have some:
Which one of the following situations can be addressed by designing objects with polymorphism in mind?
Ans. 1. The application needs to run on Linux and Windows without being recompiled.
2. The system needs to communicate with non-Java applications over Unix sockets.
3. The objects are part of a distributed system that uses the RMI functionality.
4. The application development is using an API that is currently in Early Access state, but final deployment will require the finished API.
5. In a three-tier application, the data layer has to support different underlying databases, such as Oracle, Sybase, Informix, and Postgres.
Regards
Shila
Thanks Anthony !
It makes more sense to me now.
Regards
shila
Thanks Anthony
But what will make increment() in the above code as thread-safe?
Thanks Yogesh, Val ,Anthony and Akash
So similary in the following piece of code if I want to make method increment() as thread-safe, we should declare increment() as synchronized.
class Counter {
int count = 0;
int increment() {
int n=count;
count = n + 1;
return n;
}
}
Regards
Shila
Hi Guys,
I am new to this forum. Recently I came across a problem about ThreadUnsafe. Can anybody help to correct this. Here is the code:

public class ThreadUnsafe {
private static int commonCounter=0;
public int getCount() {return commonCounter;}
public void addCount(int val) { commonCounter+=val;}
public void subtractCount(int val)
{ commonCounter-=val; }
}
Here what change will make the class defined above thread-safe?
Regards
shila