Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class SideBySide {
    public static final SideBySide HEADS = new SideBySide("Heads");
    public static final SideBySide TAILS = new SideBySide("Tails");
    private final String name;
    private SideBySide(String name) {
        this.name = name;
    }
    public String toString() {
        return name;
    };
    private static Random rnd = new Random();
    public static SideBySide flip() {
        return rnd.nextBoolean() ? HEADS : TAILS;
    }
    public static void main(String[] args) {
        System.out.println(flip());
    }
}


Tails
Heads
Some other output
Output can not be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Random Class - java.util.Random Package

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App