Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

casting problem from bill brogden mock exam

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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
  • 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: 4452
41
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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)
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic