After miserably failing to answer question 50 from Marcus Green's mock exam #2 I figure I'd make my first post and see if anyone knows of any good examples or exercises to help illustrate Marcus's definition. (Found here: http://www.jchq.net/tutorial/05_01Tut.htm ) Question 50: Given the folowing classes which of the following will compile without error?
Any help would be much appreciated. Thanks in advance ...
The rules are pretty simple: You can't instantiate an interface or abstract class. You can store an instantiated object in a type that is: a) itself b) its parent c) any interface implemented by itself d) any interface implemented by its parent Knowing that let's look at Marcus's example:
1 is an example of b - Object is the parent of CFace 2 is an example of b - Base is the parent of ObRef 3 is an error because you are storing an object in a variable that is its child type 4 is an example of b - Object is the parent of Base Remember, Object is the parent of everything in Java.