Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compile Time vs Run Time Assignments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compile Time vs Run Time Assignments" Watch "Compile Time vs Run Time Assignments" New topic
Author

Compile Time vs Run Time Assignments

Gerrod Bland
Greenhorn

Joined: Sep 01, 2002
Posts: 5
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 ...


Regards,<p>Gerrod Bland
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compile Time vs Run Time Assignments