Deepesh Deomurari

Greenhorn
+ Follow
since Oct 29, 2008
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 Deepesh Deomurari

Yes. You should use variable. Please specify line on which you are getting NullPointerException

1. What will happen if getSqlMapClientTemplate() is null!
2. How can you compare Object to a String(" ")? Not significant
3. count can never be null. It can be 0.

now what sense does that make?


I am not talking about variables. I must have written that I used some approach of solving such shadowing and reference related problems. Its nothing to do with Java don't treat it as Java statement.

Answer lies in the fact

2-> 66*


*-> updated because object passed in parameters i.e. We passed main's voo.doo object passed to the method, then that object is modified in that method and taken new value 66.
Take this trace:
1. voo.voolish(voo.doo) =>Passing main's voo.doo object in the method.
2. void voolish(Doo doo) { => Here doo refers to main's voo.doo object
3. doo.doolet = 66; => Main's voo.doo.doolet attribute is modified to 66.
4. doo = new Doo(); A new object is created(Method level), previous reference changed, now doo is referring to new created object!!!
5. doo.doolet = 77; doolet got value 77(Completely new object).
6.System.out.print(doo.doolet); => 77 Printed on the screen.
7. Method level object vanished.
8 System.out.print(voo.doo.doolet); => refer to main's object which we changed at line 3, so the value 66.
Remember, if we pass object as parameter then we can change their state(means attributes) in the called method.


Mumtaz Khan wrote:Deepesh,
its not Voolish.doo.doolet 2->77 .



I think we both are at same page, Volish.doo.doolet means doo object created in Volish method having variable doolet. Correct me if I am wrong.
In exams, these questions need more concentration. I used a trick of using tabular format to solve like

Variable Initialized First Step Second Step Third Step
Doo.doolet 0->55


Voo.doo.doolet 0->55 2-> 66* 3->66

Voolish.doo.doolet 2->77


Sysout : 1->55 2->66 77 3-> 66

So answer is 55 66 77 66
(I created a table but it looks little messy when posted.. So using 0 for initial 1 for Step1 and so on)
*-> updated because object passed in parameters.

Same thing can be used in reference counting to check for candidates for garbage collections.

I believe there can be much easier ways Any one can help

Oh! I haven't looked at complete question because I found the clue at very first line My fact is also true. But primary resolution is given by you . Thanks for correction .
Another interesting fact is that if you add y-- after y++ to make both values equal then also answer will be false.

Integer wrapper use only 8 bytes while comparing using == operator. Max allowed value of operand to be true is 127)
Scenario 1: Every Member object should implement Serializable .

Scenario 2: Every member object initialized by null automatically as part of object and class construction.

Scenario 4: If Dog constructor is not running in deserialization process then HOW that method call will run?

so super(“dogFood”); will never run. REMEMBER transient variables got reset at deserialization process. So constructor of Animal will be called but DOG implements Serializable so constructor of DOG will not be called.
Scenario 1: Every Member object should implement Serializble .

Scenario 2: Every member object initialized by null automatically as part of object and class construction.

Scenario 4: If Dog constructor is not running in deserialization process then HOW that method call will run?

so super(“dogFood”); will never run. REMEMBER transient variables got reset at deserialization process. So constructor of Animal will be called but DOG implements Serializble so constructor of DOG will not be called.
Similar solution
bc.ob[1] ->Object of Gabc
bc.obp[1].ob-> element of Gabc with name ob i.e. Array of Gabc
In next line you are creating array of two objects
1. new Gabc()
2. bc.ob[0] which is object of Gabc type
so bc.ob[].ob will be set to array of two variables.

One more things, sorry for last updates, at line1 parameter will not be LOST because it is still referred by ob[];

Vararg converts there argument to array so object created at line 1 will also have reference to two objects passed as parameter.
bc.ob[1] means SECOND object created at LINE 1 in parameter
bc.ob[0] means FIRST object created at LINE 1 in parameter
Good question
Lets see
MyCollection class implements Iterable<String> which is having three method
next
hasNext
and remove
Secondly, how Iterator moves?
first it checks for next variable using hasNext() which returns boolean and then it retrieve next variable using next()
so internally this process will be followed.

Now again to the loop
1. retValue has true value, so hasNext returned retValue as true
2. true returned means next object is available, so it moves to next element using next()
3. In next method two things happened
3.1 It set retValue=false(i.e. for next call of hasNext will return False!!!)
3.2 returned "TEST" as next String
4. System.out.println printed returned variable("TEST").

Hmm..

lets see what happened on a+b
a is a String and b is an StringBuilder(i.e. OBJECT)
a+b=> a +b.toString();
(remembered we generally use OBJECT NAME to print with system.out.println which takes STRING argument like system.out.println("Object Created:"+obj) so always in concatenation with the String, result will be String.

it can be taken as
(a+b.toString()) , which will return an object of type STRING.
As you may be aware that you can pass String to object reference.
So Object d=newly created STRING.

Similar explanation for second one
assert is disabled. (Its by default operation).
Generally, assert related information will be given in the question If NOT, then question may be testing knowledge of default behavior.
Only ONE Object, so total will be three, two are referred by member Object of newly created class(ob).
remember one constructor run at each object creation.
It NEVER depends on number of parameters, parameters are used for MATCHING the constructor type.
Compile error in "instanceof" operator occur only when both operand belongs to different inheritance tree
So String, Object belongs to same inheritance tree.


But it will not work::

for loop is throwing compile time error because, when you called addBirds method it returned Map Without Generics. So KeySet method returned OBJECT not String

remember if we replace bs.keySet with birds.keySet() at line 12 then it would have worked.

--Deepesh Deomurari
SCJP 1.5 -94%