Menu
Topics Index
...
`

Dhoom32397


If you need explanation Read this topic

If you need Answer Take test on this topic

Dhoom32397
What will be the output of the following program?
import java.util.*;
public class Dhoom3 {
    public static void main(String[] args) {
        Katrina kaif = new Katrina();
        kaif.addObserver(new Amir());
        kaif.addObserver(new Abhishek());
        kaif.notifyObservers();
        kaif.upgrade();
        kaif.deleteObserver(new Amir());
        kaif.notifyObservers();
    }
}
class Katrina extends Observable {
    void upgrade() {
        setChanged();
    }
}
class Amir implements Observer {
    public void update(Observable arg0, Object arg1) {
        System.out.print("Kat | ");
    }
}
class Abhishek implements Observer {
    public void update(Observable arg0, Object arg1) {
        System.out.print("Kaif <> ");
    }
}

A. Kaif <> Kat |
B. Kaif <> Kat | Kaif <> Kat |
C. Kaif <> Kat | Kaif <>
D. No output is generated
E. Compilation Error or Runtime Error
Topic: Java Observable

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A is the ans. though v r calling Amir class firstly .we used upgrade and deleting of amir.so now Abhishek class methods r printed ie; KAIF<> and then amir ie; kat|

Posted by Shabaaz Shaikz    2014-06-02 13:41:26


answer is b because kaif.upgrade is called only once which results in no change of output for kaif.notifyobservers()

Posted by Shiva Goud    2014-06-02 13:41:50


ans a. addobserver adds objct to the invoking list.observer interface usd 1st amir class updatd .again usd with abishk class and now updated .tis updated value printd kaif<>,
thn deleteobsrvr remove the invoking objct of amir class and notifyobserver list ve ly abishk class n prints output kat i

Posted by Maheshwari Natarajan    2014-06-02 13:48:03


Answer : E Compilation_Error
i think we wont be able to add the classes Amir and Abhishek as the addObserver() will take only one Observer parameter and this doesn;t match with the method invocation ( new Amir() , new Abhishek() ) being passed

Posted by Deepak Kumar Yadav    2014-06-02 13:48:35


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-03 04:32:42


© meritcampus 2019

All Rights Reserved.

Open In App