Vaibhav Chauhan

Ranch Hand
+ Follow
since Aug 16, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Vaibhav Chauhan

Hi Jesse,
so far i think dat the reason given by meg is the only reason why local variables of method can't be accessed within method local inner class but by reading the post to which you have given the link, it seems that the reson why we cannot access local variables from method local inner class is that its a BAD THING (metioned in that post) as there is copy of local variable stored in private variable of inner class which can be modified if the local variable is not declared final, therefore java enforces the programmer to mark local variable as final variable.

So what is the true reason that prevents us to access method local variables within method local inner class ??
ya you can postpone it.... one of my friend did it , He went to the exam centre for that.... i dont know if there is any other process as well.
here b should show the value '2147483648' but the maximum positive number is '2147483647'.
Actually these values lie in circular form so the desired result is 2147483648 i.e. '2147483647+1' so when we add 1 to 2147483647, the value becomes -2147483648.

try this program



output:
-2147483648
2147483647


i hope you got it.
thanks henry.... uu clarified our doubts.
Tommaso,

following ccode works fine:



so the reason that you have given doesn't work. Anyway when we compare primitive types, the data types get converted to the bigger data type.

Anyway this question is too good i think.

Hope for a reply
oops !!! I didn't look at abstract word.... the solution that i proposed is for non abstract class...
Not at all..... you are not required to override the superclass method before overloading it. Use the same method name and different signature in subclass method and still this will be considered as overloading.

hope you got it.
Thanks Bert for your reply. But do you mean that if we get the same question in exam, does it mean that no object is eligible in this question for GC?

Thanks in advance for your reply.
Hi all ranchers,

I am facing some problems regarding IO, Thread and Collections topic as I am new to these topics. Can anyone please suggest me any good source of questions for these topics?
Thanks for all your support.
I think the answer is that 10 objects will be eligible for GC because once the method returns, there is no reference which can refer to any of the 10 objects created as all the references are local.
Ans to Q6: Here we are simply assigning a String object to Object Class reference. At the run time, overridden toString() method(overridden by String) gets called because overriding has something to do with the object not reference.

Ans to Q 41: If we don't use static keyword, we can't access protected member through superclass reference, surely we can access protected member in subclass but through subclass reference only.
We can have static method inside which we can invoke the private constructor hence we can create the instance directly by invoking static method.
congratulations buddy.....

please share your experience with us.
17 years ago
Object level lock: this is the lock that any thread aquires over nonstatic synchronized method. Any thread can invoke the synchronized method for different object other than the object that has invoked the synchronized method.

Class level lock: this is the lock that any thread aquires over static synchronized method. No thread can invoke the synchronized method for any object until the first thread which is having the lock releases it.



We need not to worry about locks during coding, it is decided by compiler depending upon keyword static.

I know only two locks, if there is any other locks please respond with answer.


hope you got it.
Go through synchronization topic if you haven't already that.

if a thread invokes a synchronized method, the object through which the thread has invoked the method holds the lock of that method( i.e. no other thread can invoke that method using same object, though it can invoke it using different object)

hence java makes sure that any object is not being changed by another thread when one thread is modifying the object( modifying the object inside the synchronized method body).

hope you got it.