Array

Description

OCA Java 7 SE OCA Java SE 7 (Arrays) Flashcards on Array, created by alim586 on 17/06/2015.
alim586
Flashcards by alim586, updated more than 1 year ago
alim586
Created by alim586 almost 9 years ago
2
0

Resource summary

Question Answer
An array type can be? Primitives Interfaces Abstract class Concrete class
Once allocated, all the array elements store... their default value. object = null int = 0 double = 0.0 char = /u0000 boolean = false
Initializing an one-dimensional array with for loop int anArray = new int[3]; for(int i = 0; i < anArray.length; i++){ anArray[i] = i+1; }
Initializing an array int anArray [] = new int[2]; anArray[0] = 1; anArray[1] = 2;
Initializing an multi-dimensional array with nested for loop int[] multArray[] = new int[5][6]; for (int i = 0; i < multArray.length; i++){ for (int j = 0; multArray[i].length; j++){ multArray[i][j] = i+j; } }
Initializing an multidimensional array int[][] multArray = int[2][3]; multArray[0][0] = 10; multArray[0][1] = 11; multArray[0][2] = 13; multArray[1][0] = 12; multArray[1][1] = 13; multArray[1][2] = 115;
What happens when you try to access a nonexistent array index position? Code will throw a runtime exception ArrayIndexOutOfBoundsException
Combining array declaration, allocation, and initialization one-dimensional array int[] anArray = new int[]{0,1,3,4}; multidimensional array int[][] anArray = new int[] { {0,1,2}, {3,4,5} };
What happens when you access: multArr[1][1];? int[][] multArr = new int{{1,2},null,{2,5,8}}; null pointer exception multArr[1][1] doesn't exist
What values do elements of Interface type array store? either null or object that implement the interface type
What values do elements of Abstract class type array store? its element are either null or objects of concrete classes that extend the relevant abstract class
What values do elements of object type arrays store? Because all classes extend the class java.lang.object, elements of an array whose type is object can refer to any object. And null is also a valid element !
Show full summary Hide full summary

Similar

Java Week 5 Object Oriented Programming
Troy Bowlin
Java Practice 1
Ummm No
Computer science unit 2
Somto Ibeme
Java Practice 2
Ummm No
Servion - Java Questionnaire
rohit.benedict
Java Core. Basics
Gadget
Programming Review
Shannon Anderson-Rush
Useful String Methods
Shannon Anderson-Rush
JavaScript Fundamentals
Andrew Watters
Programming in Java
Faheem Ahmed