File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question, reference, package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question, reference, package" Watch "Question, reference, package" New topic
Author

Question, reference, package

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707


I feel it difficult to understand the things;
Is this something talking about what reference variable can be passed to the method?

Please help.


Source
Thanks,
[ May 01, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
A and B are fine for obvious reasons
C causes compiler error
D is fine given that all we do is assign it to the lastEvent.
However if one would try to use it, you would get a NullPointerException.

Given the code:- D should be fine as lastEvent is not used.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The point of this question is that if a method expects a reference parameter of type A, then you can send any reference parameter which has the "is a" relationship with A.

One thing this means is that you cannot send a superclass of type A to the method.
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
Man!!! you edit your posts in fraction of a second... thats fast..

Yup it deals with inheritance, the kind of reference variables used.

So Reference of the Base class or subclasses would be fine.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Thanks Swarna and Keith for your prompt reply.
It helped me to get the question correctly.



Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question, reference, package