Hi,
***** Exercise 6 *****
(
PS: The book name is
OCA Oracle Certified Associate JAVA SE 8 Programmer I Study Guide from
Jeanne Boyarsky and
Scott Selikoff)
(
PS: The exact question of the exercise below 6 below is: "What is the result of the following code? //Answer is: roar roar!!!)
Code:
I'd expect this code not to work: the variables
roar1 and
roar2 are defined inside the
main() block of code, hence they have local scope.
I know that "smaller contained blocks can reference variables defined in the larges scoped blocks"(page 32), but that's not the case as
roar() and
main() are at the same level.
Question: How can
roar() sucessfully reference to them?
***** Exercises 32/33 *****
On exercises 32/33 we have "inverse" ways of printing the desired formatted date:
I will not print the enire code, as the relevant part for my question is the order in which the exercises use
.format, the
LocalDateTime f variable, and the
DateTimeFormatter d variable.
Exercise 32 codes System.out.print(
d.format(
f));
Exercise 33 codes System.out.print(
f.format(
d));
I'd expect the way exercise 33 prints it to be incorrect, but it isnt. I then also decided to print ex 33 they way I expected it to be and it also works. It seems more intuitive we'd apply .format(f) to a date, then the other way around.
Question: Why is interchangeable?
Thanks