Search Header Logo

Core Java Quiz - 2

Authored by Gnaneshwar Reddy

Other

University

Used 3+ times

Core Java Quiz - 2
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is an ArrayList in Java?

A fixed-size array

A resizable array

A linked list

A map data structure

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How is memory allocated for elements in an ArrayList?

Elements are stored in a continuous block of memory

Elements are stored in separate memory locations

Elements are stored in a binary tree structure

Memory allocation depends on the ArrayList's size

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How does the ArrayList differ from a regular array in Java?

ArrayLists can hold primitive data types, while arrays cannot

ArrayLists are dynamically resizable, while arrays have a fixed size

ArrayLists are faster for element access compared to arrays

ArrayLists cannot store objects, only arrays can

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What's the initial capacity of an ArrayList, and what happens if you exceed this capacity?

Initial capacity is 0, and exceeding it results in an exception

Initial capacity is 10, and exceeding it causes the ArrayList to automatically resize

Initial capacity is based on the size of the first element, and exceeding it causes a compile error

Initial capacity is unlimited, and exceeding it causes a memory overflow

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you add an element to an ArrayList?

Using the addElement() method

Using the add() method

Using the insert() method

Using the push() method

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the below ArrayList program?

import java.util.ArrayList;

import java.util.List;

public class Test {

public static void main(String[] args) {

ArrayList<String> al = new ArrayList<String>();

al.add("A");

al.add("B");

al.add("A");

al.add(null);

System.out.println(al);

}

}

Compile time error

[A, B, null]

[A, B]

[A, B, A, null]

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Find the output of the below ArrayList program?

import java.util.ArrayList;

import java.util.List;

public class Test {

public static void main(String[] args) {

List<String> al1 = new ArrayList<String>();

al1.add("A");

al1.add("B");

List<String> al2 = new ArrayList<String>();

al2.add("P");

al2.add("Q");

al1.addAll(al2);

System.out.println(al1);

}

}

[A, B]

[P, Q]

[A, B, P, Q]

[P, Q, A, B]

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?