Abhinav Yadav

Ranch Hand
+ Follow
since Nov 08, 2009
Merit badge: grant badges
For More
India
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 Abhinav Yadav

This is happening because the class Animal is a super class and it has only one method and that is
and Dog is its subclass ,its simple to explain that why compiler shows error it is because when object of Dog is created in
it is stored in reference of type Animal
and in case of function overriding it depends upon the reference variable used to call the function and not upon the object it is storing.
Since there is no function named playDead() in the class Animal thus error is shown.

Wouter Oet wrote:Eh Math.pow() maybe.


thanks
it worked
but what should i do to make all the numbers to be printed and not the exponential part
eg if i did

what should be done to print the exact no. i.e
548815620517731830194541.899025343415715973535967221869852721
13 years ago
how can we directly find the power of a number in java ,as in C language there is a function math.pow() is any such type of function provided by java?
13 years ago
hope you got it
hi Phil ,
here is the code that it should look like

what is happening is that the the HashSet overrides the hashcode() and equals() method ,so if you try to put duplicate elements in a HashSet it would be considered as a single value and only one of them will exist ,therefore when we delete 1 there is only one element left and that is 2 and if we remove that also we get size of set as zero,it is one of the reasons why set is different from lists which can contain duplicate elements.



Sandra Bachan wrote:Actually, I am unable to grasp your code.

Are we supposed to pass arguments to the execution of the program, i.e.

java b arg1 arg2 arg3

How is this program supposed to work. I am perplexed


actually no!!
run it in your terminal like this
c:\>java b (no of objects to be created i.e here 5) (size of each object)
here i am providing screen shots of outputs

1). infinity
2). ArithmeticException
3). Compile time error
4). infinity
5). -infinity
6). -infinity
7). ArithmeticException
8). NaN(not a number)
9). NaN(not a number)
10). compile time error

this is so may be because of the object hiding since s is initialized in parent as well as child class so its the s of child class which is being called and not of parent
@sahil nice question buddy, to me every line seems to give error except that last one,which will surely be true ,but the two sirs have already given the answers but i will also try ,here it goes:

Line 1, StringIndexOutOfBoundsException
Line 2, Should be false
Line 3, Char literal being empty compile time error
Line 4, Compile error,but cant think of a reason
Line 5, this should not print anything as there is no substring at 5
Line 6, may be index out of bounds
Line 7, true ,both the objects refer to same sequence of characters hence interned ,therefore its should be true

Sahil Rally wrote:I am concerned about "What you wrote in last" . Whether second time "abc" would go into pool as abandoned object or not !!!


Ankit sir has clarified your doubt That

doesn't goes into the pool
its only the declarations of the type

are stored in pool
Hope you got it now!

Peter Taucher wrote:Doesn't the hashCode method of String base on it's content? And I think StringBuilder doesn't provide an implementation of hashCode, so it uses Object's method. Therefore the result should be 'false true'.


Hmm i think You are right,but let others also do the work.
and @sahil your answer is not correct.

Sahil Rally wrote:Reference :- SCJP 6 k&b pg 434

It is written that,

String s= "abc" ;//Line 1 //creates one strig object .

In this simple case , "abc" will go in the pool and s will refer to it.

String s = new String("abc"); //Line 2 // creates two string objects

One object in non-pool memory
Another one in Pool memory

I have following two questions

Q1:- Why an object is also placed in a pool memory.

Q2:- As said by k&b that line 2 would create 2 objects in which one of them will go into pool, but after line 1 we have "abc" already in the pool, then why one more. Or the two statements are independent of one another.


yes the two statements are independent of one another
you will understand by this example
when you do
then since these two strings have same character sequence so only one string object is shared by all string valued constant expressions.Such strings are said to be interned ,i.e they they share a unique string object if they have the same content,and the String class maintains a private pool where such strings are interned.
Now,let us take

This constructor creates a new String object and therefore it does not intern the string i.e it will not share the same value as shared by a and b.
and if you do

but i dont know whether another object goes into pool ,and if it goes then it would have printed true in above code ,but it doesnt.

Emanuele Ghe wrote:Hi,
the best thing for you is to try the program yourself in spite of making this kind of posts.

You will learn a lot more trying things in spite of asking.

You should ask only when, even trying, you can't understand something, or you need some kind of clarification.



hi ,
i have tried and understood the program,the basic idea to give this question was to make other aspirants aware of concepts that are minute and sometimes can be missed thereby just running the program and getting the answer wont help until it is not understood.Trying this program without compiling would let you know the depth of concepts,thats it ,if it does any harm to post an important question then i would rather post these good questions under some another tagline.

What should be the output of the following program:

Note:There are no compilation errors.

Reference to Rules