Java Arrays, Abstract Classes & Interfaces – Review Flashcards

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/29

flashcard set

Earn XP

Description and Tags

30 Q&A-style flashcards covering Java abstract classes, interfaces, one- and two-dimensional arrays, object arrays, array processing, and method parameter passing.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

30 Terms

1
New cards
  1. What is an abstract class in Java?

A class declared with the keyword "abstract" that cannot be instantiated and may contain abstract methods as well as concrete ones.

2
New cards
  1. What is an interface in Java?

A reference type similar to a class that can declare only static constants and abstract methods; it cannot be instantiated.

3
New cards
  1. Can abstract classes and interfaces be instantiated directly?

No, both abstract classes and interfaces cannot be instantiated.

4
New cards
  1. Why would you use an array to store 100 Student objects instead of 100 separate variables?

An array provides a single variable name, organized contiguous storage, and efficient indexed access for all 100 objects.

5
New cards
  1. What three key traits characterize a Java array?

A single name, elements all of the same data type, and indexed (subscript) access to each element.

6
New cards
  1. Which notation identifies a specific element in an array?

Subscript (index) notation using square brackets, e.g., mark[10].

7
New cards
  1. What loop structure is most commonly used to traverse an array?

A for loop.

8
New cards
  1. Give the general syntax for declaring and creating an array in one line.

BaseType[] arrayName = new BaseType[length];

9
New cards
  1. What default value is assigned to numeric (int, double, etc.) array elements?

0 (zero).

10
New cards
  1. What default value is assigned to boolean array elements?

false.

11
New cards
  1. What default value is assigned to char array elements?

'\u0000' (the null/blank Unicode character).

12
New cards
  1. What default value is assigned to array elements whose base type is a class?

null (no object reference).

13
New cards
  1. What runtime error occurs if you access an index outside 0 … length-1?

An IndexOutOfBoundsException is thrown, terminating the program unless caught.

14
New cards
  1. How do you obtain the size of an array called mark?

By reading mark.length

15
New cards
  1. After creation, is a Java array’s length changeable?

No, Java arrays are fixed length once allocated.

16
New cards
  1. How can you create an array whose size is decided at runtime?

Read the desired size (e.g., with Scanner), then execute: int[] mark = new int[size];

17
New cards
  1. Write the declaration that creates a 4-row, 5-column double array named payScaleTable.

double[][] payScaleTable = new double[4][5];

18
New cards
  1. How would you access the element in row 2, column 1 of payScaleTable?

payScaleTable[2][1]

19
New cards
  1. Internally, what is a two-dimensional array in Java?

An array of arrays; each row is a separate one-dimensional array object.

20
New cards
  1. When you execute Person[] person = new Person[20]; what is allocated?

An array capable of holding 20 Person references, all initially null; no Person objects yet exist.

21
New cards
  1. What happens after person[0] = new Person();

A new Person object is created, and its reference is stored in element 0 of the array.

22
New cards
  1. Which loop was used to fill the Person array with data?

A for loop iterating from 0 to person.length – 1.

23
New cards
  1. What simple algorithm was demonstrated to find the youngest and oldest Person objects?

Maintain minIdx and maxIdx, iterate through the array comparing ages, updating indices when a younger or older person is found.

24
New cards
  1. Describe Deletion Approach 1 for removing an object from an array.

Set the target element (e.g., person[delIdx]) to null, leaving a "hole" in the array.

25
New cards
  1. Describe Deletion Approach 2 for removing an object from an array.

Copy the last element’s reference into the element to delete, then set the last element to null—compact but order-changing.

26
New cards
  1. How was a linear search for a Person named "Latte" implemented?

Use a while loop that advances until a null slot or a matching name is found, then check success or failure conditions.

27
New cards
  1. When an array is passed to a method, what is actually passed?

The reference (address) to the array object, not a copy of the array itself.

28
New cards
  1. Inside the called method, how does the parameter relate to the original array?

The parameter is another reference to the same array, so the method can directly access and modify the original elements.

29
New cards
  1. After the method finishes, does the caller’s reference still point to the same array?

Yes; the reference in the caller remains unchanged and still refers to the same array object.

30
New cards
  1. How can you initialize an array during declaration with explicit values?

Provide a comma-separated list in braces, e.g., double[] reading = {5.1, 3.02, 9.65};