Owl Teach Yourself Java 2 in 21 Days Pro, Third Edition
HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / THANKS
ROGERS CADENHEAD

Day 24: Writing Java 1.0 Applets

Certification Practice

Each chapter of the book ends with a Certification Practice question that's comparable to what you could expect to be asked on a Java certification test. Here's the answer for chapter 24:

Answer (a) is correct. The compiler will report a "possible loss of precision" error because the literal 1.5 is considered to be a double, which is larger than a float. To correct the error, change the literal from 1.5 to 1.5F.

Answer (b) is incorrect. Even though the Formula() constructor is called with a String argument in the application's main() method, that's permissible. String is a subclass of Object -- like all Java objects -- so Object is a compatible type for the method argument.

Answer (c) is incorrect. It does cause an error, but not when the class is compiled. When it is run, this line will cause a ClassCastException because you cannot cast an Object to an Integer.

Answer (d) is incorrect. The line is correct -- the object type of the application can be Formula or any of its superclasses. Edit

Return to Day 24

HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / THANKS

Valid HTML 4.01!

Valid CSS!