What will be the result of the following code compilation and execution?

import java.util.*;
public class Test {
    public static void main(String[] args) {
        List buf = new ArrayList(2);

        System.out.print(buf.size());

        buf.add(10);

        System.out.print(buf.size());

        buf.add(20);
        buf.add(30);

        System.out.print(buf.size());
    }
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes