I came acroos this questions in Brogden's site.
import java.util.*;
class ApBase extends Object implements Runnable{public void run() {}}
class ApDerived extends ApBase implements Observer {public void update(Observable o,Object arg ) {}}
class A {
public static void main (
String args[]) {
ApBase abase = new ApBase();
ApDerived ader = new ApDerived();
}}
The question was 'Which of teh following will compile and execute without error?'
The options given are:
1)Object obj = abase;
Runnable rn = obj;
2) Object obj = abase;
Runnable rn = (Runnable)obj;
3)Object obj = abase;
Observer ob = (Observer)abase;
4)Object obj= ader;
Observer o = obj.
The correct ans is b). I understood that 1) is a wrong option.
Could you help me in finding out why b) is right and why c) and d) are wrong?
Also could any one sugegst a good reading material on this topic?
I am totally lost