Ok, now I'm a little confuse as to why is Exception legal. I mean there is no checked exception that the code can throw that is not already a HurtException, right?
I always though that as long as the exceptions declared in the catch blocks argument are in order from the most specific to the most broad, everything is ok. Like in the example below:
Further more in the book at page 310, there is actually an example about something similar, but the exceptions there are unchecked exceptions. As a general rule: if the exceptions are unchecked it compiles, but if not it does not?
First of all, the book and it's content have been very helpful, but i don't know about the online tests. This is the last mistake I've encounter (as in not the only one). I hope I'm mistaking, but I don't think so:
The question is:
Which of the following can fill in the blank to make the code compile? (Choose all that apply)
Correct answers according to the test are only Exception and RuntimeException, when in it is clearly (according to my IDE) that with also LimpException, the cod compiles. Am I missing something here? I mean I get a warning from the IDE, but it compiles.
Yeah, but the method "method()" is overridden at line 25 in Sub. So it is not Super's method anymore. It should be Sub's method. If you look at line 14, "anotherMethod()" is also overridden and the output is "In sub". Like it should be. I'm sure that if I write throws Exception is the main method declaration, and put "System.out.println("In sub");" also in the "method()" at line 25, the code will compile and the output will be "In sub".
I was wandering if you guys have an explanation on what is happening behind the curtains. Why doesn't the compiler accepts the call at line 16, considering that the method is overridden and is no longer the one from Super.
I don't get it. Why does "super1.method();" not compile? The method in the Sub is called and it doesn't declare any exceptions.
Are the exceptions thrown by the method in Super inherited by the method in Sub? And if so, why "sub.method();" compiles? Or is it more of a technicality? I though that after the method it's overridden, that method "belongs" to the object, not to the reference anymore. Polymorphism, right? I knew that Java still takes a look at the method in Super just to make sure I don't declare a broader exceptions, but I thought that was it.
I've searched the internet and I couldn't find a real answer. I'm currently in Germany, and I want to take my exam here, but will I be able to choose English as the exam language? Or is the language country dependent? I mean, I'm just nervous that I will find myself in the exam room and obligated to take it in deutsch. My deutsch is Ok-ish, but I don't want to risk it...
First of all I'm not sure if my question is actually about method overriding because I'm not sure what causes this. I understand why the result is(I mean how the overriding and hiding works) :
What I don't understand is why is not:
4 Beta 44
44 Beta 44
Operations in a System.out.println(), are done from left to right in this case, no? So "4" should have been first because it was hidden; then the method from Beta class comes next, because is was overridden: Beta 44; then the println from inside the method; and last the return from the method: 44, right? For the next System.out.println() is the same process only that h is 44....
Why is "System.out.println("Beta " + h)" from the b.getH() read first, then "b.h", then the return "44" from b.getH() and last the println from the original System.out.println()?