Thursday, August 5, 2010

Operators: Feline.java

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 4, Question 4

Modified code


It compiles and runs. Output

 72 foo425 50foo


line 5: concatenation runs from left to right, and if either operand is string, operands are concatenated
line 6: same as line 5, because foo() returns a String
line 7: concatenation runs from left to right and if both operands are numbers they are added together; x is unboxed to 42, then added to 8

No comments:

Post a Comment