• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

casting problem from bill brogden mock exam

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please read the following code
----class ApBase extends Object implements Runnable
class ApDerived extends ApBase implements Observer
two variables are created as follows
ApBase abase=new ApBase();
ApDerived aDer=new ApDerived();
which of the following will compile without error ???
1. Runnable rn=aDer;
2. Runnable rn2 = (Runnable) aBase;
3. Observer ob=aBase;
4.Observer ob2= (Observer ) aBase;
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the right answers are 1 and 2, right?. Because ApBase implements Runnable and ApDerived implements Runnable because is an extension of ApBase, but There is NO WAY ApBase implements or knows about Observer, so not even the cast will work.
Am I right?... feedback please.
thanks.
 
Enthuware Software Support
Posts: 4897
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are correct.
-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Try out the world's only WebCompiler!
www.jdiscuss.com
 
preeti dengri
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where can i get more info on casting and conversion (for every such possibility)
thanks all
preeti
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't see the original question.
So it depends on what the question want...
4) can pass compilation but will give you run-time error... So if asked which one can compile 1) 2) 4), if asked which one can run, only 1) 2)
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic