OOP - session 2.1 - JVM, Array, Stack
Quiz
•
Computers
•
University
•
Medium
Kasmir Syariati
Used 1+ times
FREE Resource
Enhance your content in a minute
21 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Which of the following is the correct way to declare and allocate an array of 10 integers in Java?
int arr = new int[10];
int arr[] = new int[10];
int arr = [10];
int[] arr = int[10];
Answer explanation
In Java, arrays are declared by specifying the data type followed by square brackets (which can appear after the type or the variable name) and are allocated using the new keyword with the size inside square brackets.
2.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Which statement best describes arrays in Java?
Arrays are primitive types and their size can be changed at runtime.
Arrays are objects stored on the heap and have a fixed size once created.
Arrays are automatically resized like Python lists when elements are added.
Arrays are stored in the stack and allow dynamic memory allocation.
Answer explanation
Unlike Python lists, Java arrays are objects that reside on the heap, and their size is fixed upon creation. They are not dynamically resizable.
3.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
int[] numbers = new int[5];
What are the default values of the elements in the numbers array?
They are undefined and accessing them will cause a runtime error.
All elements are set to 0.
All elements are set to null.
They contain random garbage values.
Answer explanation
In Java, when an array of primitive type (such as int) is allocated, each element is automatically initialized to a default value (0 for numeric types).
4.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Given an array declared as
String[] names = new String[3];
what happens if you try to access names[3]?
The compiler automatically resizes the array to include the index.
It returns null because the element has not been assigned a value.
It throws an ArrayIndexOutOfBoundsException at runtime.
It returns an empty string.
Answer explanation
Java enforces strict bounds checking on arrays. Since valid indices for an array of length 3 are 0, 1, and 2, attempting to access names[3] will result in an ArrayIndexOutOfBoundsException.
5.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Which of the following statements about multi-dimensional arrays in Java is true?
Multi-dimensional arrays in Java are arrays of arrays, meaning the subarrays (rows) can be of different lengths (jagged arrays).
Java does not support multi-dimensional arrays.
Multi-dimensional arrays in Java are implemented as linked lists under the hood.
Multi-dimensional arrays in Java are truly multi-dimensional like in C, and their rows must all be of equal length.
Answer explanation
In Java, multi-dimensional arrays are implemented as arrays of arrays. This means each subarray (or “row”) can be independently allocated, allowing for jagged arrays where rows can have different lengths.
6.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Which of the following best describes a stack data structure in Java?
A data structure that follows the Last In, First Out (LIFO) principle.
A structure that supports random access to its elements.
A non-linear data structure optimized for search operations.
A data structure that follows the First In, First Out (FIFO) principle.
Answer explanation
A stack is a linear data structure where the most recently added element is the first to be removed, following the LIFO principle.
7.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Which Java class provides a direct implementation of a stack?
java.util.ArrayList
java.util.Stack
java.util.LinkedList
java.util.Queue
Answer explanation
The java.util.Stack class is the built-in implementation in Java that provides methods like push(), pop(), and peek() to perform standard stack operations.
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
20 questions
Information Management - QUIZ
Quiz
•
University
18 questions
AI 900 - pt 1
Quiz
•
University
20 questions
DIAGRAMAS UML DE CLASE
Quiz
•
University
20 questions
04-JS циклы while, do..while, for...
Quiz
•
University
20 questions
File Extensions
Quiz
•
9th Grade - Professio...
20 questions
Programming Concepts in C - Quiz-II
Quiz
•
University
18 questions
PBO Inheritance Episode 2
Quiz
•
University
20 questions
FRAMING,Bit Stuffing, PPP,HDLC,
Quiz
•
University
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
6 questions
FOREST Self-Discipline
Lesson
•
1st - 5th Grade
7 questions
Veteran's Day
Interactive video
•
3rd Grade
20 questions
Weekly Prefix check #2
Quiz
•
4th - 7th Grade
Discover more resources for Computers
7 questions
Different Types of Energy
Interactive video
•
4th Grade - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
25 questions
Waves-8th Grade Physical Science
Quiz
•
KG - University
41 questions
Unit 8 Key Terms
Quiz
•
11th Grade - University
10 questions
Product & Quotient Derivative Rules
Quiz
•
University
5 questions
How to Calculate Force - Newton's 2nd Law of Motion
Interactive video
•
10th Grade - University
10 questions
Dichotomous Key
Quiz
•
KG - University
