Ravindra Mohan

Ranch Hand
+ Follow
since Mar 16, 2001
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 Ravindra Mohan

Hi Ranchers,
Well the code does compile on my JDK!!
Now if the issue in here is whether its right to create an instance of the derived class during the process of creation of an object of the base class !! Well, its a bad design to do such a thing. Its a disaster! Why? Well, you as designer, design a class to represent a real life situation. Now,
the future requirement varrant that they inherent your the attribute/behaviour of your class plus some more additional
attributes/behavior. However, you as a designer have no knowledge as to how the future requirement change!!
Let me be elaborate, in the current context, in the code provided in this thread is being made to create an object of the derived object of the derived class during the creation process of the base class this leads to infinite calls to the base class's contructor. These calls are put on the stack of the memory and eventually your memory gets exausted and no more calls are possible, the JVM throws a stack overflow exception.
I hope this clears your doubts than confuse you.
[This message has been edited by Ravindra Mohan (edited October 03, 2001).]
Yeah Ranchers,
The answer is A and C. A class with abstract method MUST be
declared as "abstract". An abstract method/ native method CAN NOT
have a body /definition.
I guess this clears this issue.
Ravindra Mohan.
GC
Hi Kaleem,
Kindly refer to your code. It will not compile due to error in line # 5 and the return type of the haq should be "Object" and not "object". I have changed the line # as <code>obj1[0]=obj;</code>
Anyway, what I understand from the code. The Float object pointed by reference "obj" will be garbage collected only after the return from the function. The reason is that at line # 5 the Float object (2.14F) can be accessed by two refernces viz., obj and obj1[0]. After the execution of line # 6. The connection to Float(2.14F) is de-refferenced by the obj. But, the object can still be reached by the reference obj1[0], so the same is still not eligible for GC. At line # 7 you are returning the object's reference to the callee function, so "null" is returned. Finally, at line # 8, the function returns so , the GC must release all the locally created object's that are unreacheable , in the current code this means that Float(2.14F) object must be GC'ed.
Hope this clears your doubt.
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited September 27, 2001).]
Hi Antii,
You are right. Infact, when you take the SCJP you are asked to submit
the non-disclosure of questions. If you choose "no" in that quesion then your score is invalidated. That means that you are
governed by the secrecy. It is for that reason JavaRanch does not allow questions for actual exams to be published in here.
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited July 27, 2001).]
Hi Guoqiao,
The reason is that the <code> toString() </code> method of <code>Object</code> class returns a new Object of the string representation of the object being passed as an argument.
Generally most classes overload this method as per their specific requirement. In the case of String class this is not
provided for, so the Object class's toString is called.
Further, the "==" operator checks the memory location of the
object and does a "shallow" comparison and returns true "if"
both the ojects have the same memory location else it returns
false. In the question you posted the toString() method returned
saperate string object which obviously have different memory locations and hence the result "false" is displayed at standard
console.
Hope this helps.
Ravindra Mohan.
Good Work Nan sh,
Looking forward to more such mock test.
The multiple selections are not getting
selected while answering the choices,
hence while selecting the score option
it giving wrong answer.
Ravindra Mohan

[This message has been edited by Ravindra Mohan (edited July 23, 2001).]
Hi Folks,
Let me take a shot at this.
This question should be seen in the light of :
1. Process and order of initialization of creation of objects. : Class variables are loaded first that is, static variables are initialised. Final variables come next.Instance variables are initialised later and finally constructor is called.
For example look at the fol :


2. Method overiding.:
When you refer a to derived class object by the reference of base class then the method call is determined by the type of the Object (ie, the derived class's object).
Now as regards to this question.
Instance variable of <code> class A </code> viz., <code>AVar</code> is set to default "0".
You create an of the derived class,so the constructor of base class is implicitely called by a call to <code>super(); </code> as the first statement in the derived classes constructor. So, we get the display "AAA". After this is done,the call to <code> doSomething() </code> is depends
upon the type of object (as explained in (2) above) viz.,
<code>class B's doSomething()</code> is called.
The forward reference to instance variable <code>BVar</code>of <code>class B</code> is set to "0" and accordingly the display "BVar= 0"is made. This completes the constructor
execution of <code>class A</code>. Next in the
order of execution is the instance variable <code>BVar</code> of <code>class B </code> is set to "2222". After this the constructor of <code>class B</code> is called and we get the
display of "BBB". After this anather call to <code>doSomething()</code> is made so we get the display "BVar=2222".


Hope this clears your doubts..
Ravindra Mohan

[This message has been edited by Ravindra Mohan (edited July 23, 2001).]
Hi Camaron,
As Kasper has correctly pointed out, the return type should
always preceed the method name. All the other modifiers can
have any order. But, you cannot have more that one modifiers
like public , protected, private.
e.g. You CANNOT declare a methdod like the following
<code>public protected void doubleModifierMethod() </code>.
Hope this clears the issue. Please reveert in case more
clarification is sought on this.
Ravindra Mohan.
Hi Camaron,
A clarification here. Static method are restricted to use ONLY
static and final static fields. However, no such restriction exists for the non-static methods. Hence, ONLY choice (c) is correct. Choice (D) is incorrect.
Hope this clears this issue..
Ravindra Mohan.
Hi Rahim,
Well , I am fed up with this so called paki movement. Shows
the amount of frustration there. I would refrain for going
into specifics, as it will spoil the spirit of this forum. If
you ask me the "good word" for the site. Well its "SHAME"!.
Yeah I am saying it loudly. Learn to give people their rightful
due.
Ravindra Mohan.
Hi Gaurav,
As parmeet has rightly put it. A certificate will not essentially
guarantee a job in this slowdown in the market. Ofcourse, you
need to have experience to get a good job. You already have
done some projects so taking up a job would be better. In my
opinion since you already have put in efforts so why not
take a go at the SCJP. Once you would be in job, believe
me, finding time to study would be difficult. I am saying these
from my personal experience.
Ravindra Mohan.
Congtrats Jonasson,
All the best for your future endeavours..
Ravindra Mohan
22 years ago
Hi Rajesh,
You can buy the coupen from any prometric testing center
at Mumbai. The one that I know in Mumbai is KarRox (Tel
# 500 2554/55, 500 2251). You can speak to some Ms. Radha
Sarathy.
Hope this suits your purpose.
Ravindra Mohan.
HI Sachin,


Child obj1 = new Child(); // no problem
Base obj2 = new Base(); // no problem
Base obj3 = new Child(); // please explain this in all possible situations
// i.e it's working when a method is called from
// base class or from child class
can we use instanceof operator here to check to which the obj belongs to ?


Further to what Jane said,


Hope this clears your doubt..
Ravindra Mohan.
Hi Arun,
The indian edition is available so you may buy the same.
Ravindra Mohan.