devesh singh

+ Follow
since May 08, 2001
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by devesh singh

we say that volatile changes the orginal copy of the variable i.e
reading and writing on the variable produces changes in the master copy of he variable
so does this also not happen in the case of static variable
I think ia hve got wring notions of the volatile variable
ps anyone expalin me the details of volatile keyword.
in case of Set and Maps does the hashcode and key have the same
maening . what does the hash code gives . ps explain me with an example.
1) analyze the following code
class A
static B b = new B(); // 1 B is some class
public static void main(String str[])
// some code
Q) what does the word static at line 1 means
hi ravindra ,
you say that public static void main(String ) method sinot valid
but we can have overloaded method those were the forms of stndard main() . now what to do whenthis type of ques comes in exam what is the answer to the above question
#) lass wrapper
public static void main(String [] str)
static int l; // 1
Integer I = new Integer(6);


what is wrong withh this code if i removw line 1 then its all OK
1) "last but not the least, the dead thread can be restarted
by creating an instance of Thread and passing the dead object as
the target to the constructor. Remember this may/may not be prudent
especially when your class has some computed state information. "
is this right please varify this with an example

2)Each object has only one lock. Therefore, if an object has three
synchronized methods, a thread entering any of the methods will set
the lock. After that, no thread can enter any of the synchronized
methods until the first exits the method it was executing and frees
the lock."
2)A unique monitor is associated with every object that has a
synchronized method

the abpove 2 points seems contradicting to me b'coa according to second poiunt
if each object have its unique lock then at a time both the method can
be holding there own lock but second poiunt says that no thread can enter
any of the synchronized method until the first exits the mthod it was executing and frees
the lock."
now suppose we have a synchronized mthod fn()
and there are 2 different objects of the class in which fn() is
present ob1 and ob2 now both of these have there seperate monitors
then at a time kboth can execute there seperate fn()
but I think this is wrong according to the I point
ps anyone clear this thing to me with a good example ( preferably a
working program)
3) static methods can be synchronized, and static methods use the lock belonging to the class rather than a lock belonging to any particular object.
now what does this mean in context with the above arguement???
4) what is the difference b\w sleep(milliseond) and wait(millisecond)
ps see the following code:
class base1
System.out.println("cons in base ");

base1(String s)// this is not accessible in the other classes
System.out.println("single parametre cons in base ");


class constructor extends base1
System.out.println("default of base");
constructor(String i)
System.out.println("single parameter in base"+ " " + i);

public static void main(String[] str)

base1 b1 = new constructor("apple"); //1
base1 b2 = new base1("apple"); //2

System.out.println("b1.equals.b2"+b1.equals(b2)); //3
b1=b2; //4
System.out.println("b1.equals.b2"+b1.equals(b2)); //5


Q) at line 1 b1 is object of constructor class ( child of base1) now at 4
it should give error b'coz casting of parent into child but it ghives no erroe
now at 1 when I write constructor b1 = new constructor("apple");
now it gives erroe asking for explicit casting needed why is this so???

I have doubt in the followig ques
A static method in a superclass can be shadowed by another static method in a subclass, as long as
the original method was not declared final.
a] False
b] True
answer given is true but the static method can be accessed int the child class
also through classname.methodname() then how it canbe called as shadowed
All the methods in an interface are implicitly public,static and final
a] True
b] False

answer given is true but I strongly believe that it is false
am i wrong ???