Josh Buckner

Greenhorn
+ Follow
since Feb 07, 2008
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 Josh Buckner

\d means digit
* means 0 or more of whatever comes before it

so \d*\d means 0 or more digits followed by one digit
After the constructor of A is passed sa, the sa of both objects A and B point to the same object. When the code in class B modifies the sa in B, it's modifying the same object on the heap referred to by the reference sa in the object instance of A.
I like to think of the animal analogy. Every dog is an animal, but not every animal is a dog. In your example, every B IsA A, but not every A IsA B. So you're not allowed to assign a reference variable of type B, an object of type A. Your animal could be an opossum.
The compiler error is "unreachable statement". The asserts won't cause an unreachable statement compiler error, maybe because you could always run with assertions disabled. Things like code after and outside of a while(true) or code after an explicitly thrown Throwable will cause unreachable statement compiler errors. Test this yourself by replacing the while loop with a "throw new RuntimeException();" It's fun to try to cause the compiler to complain!