Clemonte Johnstone wrote:1) Why throws Exception is not allowed if supplemented below?
Clemonte Johnstone wrote:2) Can we say that we are overriding the method declaration in the Subclass?
<br /> Well no, I don't know that one. The final "else" can't have any condition: <br /> <br /> I'm not sure what would make it a bad coding practice. Well, people will be happier if you use braces around each "then" section. But that's not what you're asking about. <br /> <br /> The compiler speed won't be an issue, really. More relevant are readability, minimizing possible programmer error, and execution speed. <br /> <br /> In a case like this, two things that jump out to me about the list of conditions are that it's exclusive (we can't have more than one condition true) and exhaustive (there must always be one true). In such cases, I see no reason not to use a simple else for the last case, since there's nothing new to test. If you've already tested for a > 0 and a < 0, the only remaining possibility (for int at least) is a == 0, no need to actually test it. But some people may find it more readably to say it explicitly. I would usually comment it: <br /> <br /> On the other hand, sometimes you may think you have an exhaustive list of the possibilities, but you don't. If variable a had been a double, then it could possibly be NaN, not a number. In which case a > 0, a < 0, a==0 are all false. So it may be best to explicitly state the condition each time, just in case one of your assumptions is faulty.
Miles Jiang wrote:We all know the standard if-else structure is like if -> else if -> else: