Menu
Question Index
...

What is the output of the following program?

import java.awt.*;
import java.util.*;
public class Guest {
    public static void main(String[] args) {
        List<Component> list = new ArrayList<Component>();
        Button button = new Button();
        button.setName("Add");
        list.add(button);
        TextField textField = new TextField();
        textField.setName("Name");
        list.add(textField);
        Label label = new Label();
        label.setName("My Label");
        list.add(label);
        Object object = new Object();
        list.add(object);
        for (Component component : list) {
            System.out.println(component.getName());
        }
    }
}


button0
textfield0
label0
Add
Name
My Label
object
Add
Name
My Label
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App