Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class ObservDemo {
    public static void main(String[] args) {
        BeingWatched observed = new BeingWatched();
        Watcher observing = new Watcher();
        observed.addObserver(observing);
        observed.counter(10);
    }
}
class BeingWatched extends Observable {
    void counter(int count) {
        for (; count >= 0; count--) {
            setChanged();
            notifyObservers(new Integer(count));
        }
    }
}
class Watcher implements Observer {
    public void update(Observable o, Object arg) {
        System.out.print(((Integer) arg).intValue() + ", ");
    }
}


(EMPTY)
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Observable

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App