What are the default values given to array elements in Java?
Answer:
Array elements are given their default values (0, false, null, '\u0000') regardless of whether the array is declared as an 1) instance or 2) local variable.
package com.java.arrays;
public class InitArray {
static int [] nums = new int[2];
static boolean [] values = new boolean [2];
static Object [] objs = new Object[2];
static char [] chars = new char [2];
public static void main(String[] args) {
System.out.println(nums[0]);
System.out.println(values[0]);
System.out.println(objs[0]);
System.out.println(chars[0]);
}
}