maya rao

Greenhorn
+ Follow
since Jun 10, 2005
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 maya rao

Originally posted by newgen pras:
Hey Rao ..
What ur saying is corret ..but since [] operator has highest precedance the code inside the [] will get execute first. .. hence the statement will be evaluated as
friends[1] = friends[1] + "is my best friend. ";
not as
friends[--index] = friends[--index] + "is my best friend. ";

Correct me if am wrong



ok that write.
means if i want o/p like this
Pluto is my best friend.
Pluto is my best friend

then i have to write like this
System.out.println(friends[--index] + " is my best friend.");
System.out.println(friends[index++] + " is my best friend.");

Originally posted by newgen pras:
See after excecuting first println statement
-- System.out.println(friends[--index] += " is my best friend.");

friends[1] will have value of "Pluto is my best friend " .this means after executing the println statement the array will look like
String[0] = "Micky"
String[1] = "Pluto is my best friend"
String[2] = "Donald" Since ur r assiging....

Hence naturally after the second println statement ..another " is my best friend." gets appended .. hence the output is " Pluto is my best friend. is my best friend."

Hope this helps you.



hi newgen

Does it mean friends[--index] += " is my best friend" works as shorthand operator.?? Like this
friends[--index] =friends[--index] + " is my best friend

Originally posted by Srikanth Basavaraju:


I believe all of you mean that these books in addition to the exams available on net... am I correct...

Thanks in advance.
Srikanth.




yes ur wriye. solving exams on net is necessary

Originally posted by amit taneja:
hi..in one of the question of javacertificate.com

------

incorrect Consider the following class definitions, which of the following can be legally placed at line 7 without causing a compile time error?


The correct answers are 2, 4, 5.

1. public class Animal {
2. public Animal() {
3. super();
4. }
5. protected Animal(int legs) {
6. this();
7. // Insert Code Here
8. }
9. }

1. public class Bird extends Animal {
2. public Bird() {
3. super();
4. }
5. public Bird(int legs) {
6. super(legs);
7. }
8. }



1. super();
2. Animal elephant = new Animal();
3. this(legs);
4. double d = Math.sin((double)legs);
5. Animal p = new Bird(4);

Answer 1 and answer 3 are incorrect. The super and this keywords cannot be used together, either one should be used and should be the first statement in the constructor. super() invokes the constructor in the base class whereas this() invokes a constructor in the same class definition.
Answer 5 can be placed at line 7 without causing a compile time error, however depending how the Bird class is instantiated the code can enter into an infinitive loop and cause a StackOverflowError runtime error.
----------
but my question is the code below this() is uncreachable...as it will call this constructor intantly on occuring this()




it is perfectly reachable. cz it will call this cinstructor and after executing that it will start executing the code below.




so they have given explanation on answer 5 ??

didn't get its meaning... and even its written to be true (how ? ) but hot it can cause stackoverflow...???




I think it will not give Stackoverflow but it will go into indefinite looping. plz correct me if wrong

Originally posted by maya rao:


.equals checks for reference equality.
first one is "Equal" cz toString doesnt creats a new string.So both r refering to same object
Second one is "Not Equal" cz trim creates a new String.So there r 2 differnet objects



Correction to the above statement
.equals checks for value equality and == checks for reference equality.
Hence the o/p

Originally posted by anil Arikepudi:
the first one o/p is true while 2nd one is false why so?



.equals checks for reference equality.
first one is "Equal" cz toString doesnt creats a new string.So both r refering to same object
Second one is "Not Equal" cz trim creates a new String.So there r 2 differnet objects