dee anderson

Greenhorn
+ Follow
since Oct 10, 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 dee anderson

because of fall through on the statements if you reverse 1 and 2 then the return null becomes an unreachable statement.

If you put a break in case 3 then it will compile, otherwise you can comment out the return null and it will compile.
Have only been working in Java 6 months, studying for this exam for 2, passed on 19 Nov.

Used K&B study guide and mock exams, which were definately harder than the real exam.

Good luck to anyone still to do it. Don't let the mocks dent your confidence.
15 years ago
I recommend you obtain a copy of Refactoring: Improving the Design of Existing Code by Martin Fowler. You can order it from amazon. Refactoring is a huge subject which cannot be adequately explained in a forum such as this.
15 years ago
remember that fruit1 is passed to transform function by value .. what happens to fruit1 inside the transform function is discarded when returning to the growFruit function
Also you are not getting 'nothing' as output, you are in fact getting

""
""
""
""
" "
""
" "

combined with prev post does this help?
a [ (a = b)[3] ] // (a=b) resolves to b!
a [ b[3] ] // b[3] resolves to 0
a [ 0 ] = 1

However, as a Side Effect of this evaluation the reference variable a now points to the array b, hence after this expression when you look at a[0] this is the same as looking at b[0], the answer being 2.
Aaah, sorry got confused with the post by Anut.

Anyway, the reason for this is that the line

System.out.println( a [ (a = b)[3] ] );

is evaluated as an expression. An expression is a syntactic construction that has a value. Expressions are formed by combining variables, constants, and method returned values using operators. Java expressions can have side-effects, which are actions that are executed when the expression is evaluated. The assignment of (a=b) is a side effect of the evaluation of the statement, therefore when you go on to then look at a[0], the assigment has taken place.
If you add the extra println then it assigns the reference of a to b so

int[] a = { 1, 2, 3, 4 };
int[] b = { 2, 3, 1, 0 };
System.out.println( (a = b)); //resolves to b
System.out.println( a [ (a = b)[3] ] ); //equivalent to (b [ b[3] ])
a [ (a = b)[3] ] // (a=b) resolves to b
a [ b[3] ] // b[3] resolves to 0
a [ 0 ]

= 1
try changing to this directory

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\srilanka\WEB-INF\
classes

and running > java com.example.Sample
15 years ago
All methods in an interface are purely abstract, they do not contain any body code. A static method can be called without making an instance of the class that contains it (class.staticmethod()).
I agree with Ankit, also when I see questions on this site, especially ones where I am not sure of the answer I will code them up and then play about with the code changing bits to see what happens until I understand exactly what is going on and why the answer is the way it is.
I had to do something similar recently and used

InetAddress ia = InetAddress.getByName(ipAddress);
return ia.isReachable(timeout*1000);
15 years ago
You seem to be confusing yourself with I pointing to strings. The issue here is not what I holds a reference to, but what holds a reference to I.

If there is no executing code which can reach an instance of I through a reference variable then that object becomes eligible for gc.

Add some code into I to return a name and put some code in m2 to print out i1.name, i2.name and i3.name.

Try to find some way of accessing A or B objects in m2, you will find this not possible because J has no valid references any more.
I believe the answer is C.

When the instance of J is created, three instances of I are created, A B, C.
J has a valid reference to each of these.


When m1 executes the internal reference of A (other) is set to B, and B to A. C is set to itself.

the second line sets J's references i1 and i2 to i3, i.e. all of J's references now point to C.

This means that although A and B hold references to each other there is no external reference
to either of them therefore they are unreachable and potentially eligible for gc.

J still has valid references to C so it is NOT eligible.