Menu
Topics Index
...
`

Dhoom3


If you need explanation Read this topic

If you need Answer Take test on this topic

Dhoom3
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 {
    public Katrina() {
        setChanged();
    }
    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.

Ans is B in amir and Abhishek class it is printed by extending dhoom3 class

Posted by Bharath Yelchuri    2014-03-25 08:53:25


Ans:B first it prints "kaif <>" then " kat |" then becaz of upgrage() say "there is no modification"  hence  print "Kaif <>" then " kat |"

Posted by Indrasena Reddy    2014-03-25 08:57:01


ans: c
kaif<>  kat is printed 1st...
after removing amir from observer ...notifieobservers() cals and print  kaif<>
output
kaif<> kat | kaif<>

Posted by Ananda Kumar    2014-03-25 10:53:47


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

Posted by Merit Campus    2014-03-26 04:26:32


© meritcampus 2019

All Rights Reserved.

Open In App