Java - ArraysWhich of the following lines correctly initializes an array of 5 integers in Java?Aint arr[] = new int();Bint arr = new int[5];Cint[] arr = int[5];Dint[] arr = new int[5];Check Answer
Step-by-Step SolutionSolution:Step 1: Understand array initialization with sizeTo create an array of fixed size, use new type[size] syntax.Step 2: Validate each optionint[] arr = new int[5]; correctly declares and initializes an integer array of size 5. Others have syntax errors or missing size.Final Answer:int[] arr = new int[5]; -> Option DQuick Check:Array initialization with size = new int[5] [OK]Quick Trick: Use new type[size] to initialize arrays in Java [OK]Common Mistakes:Missing square brackets in declarationNot specifying size when using newUsing parentheses instead of brackets
Master "Arrays" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Arrays - Common array operations - Quiz 2easy Arrays - One-dimensional arrays - Quiz 9hard Command Line Arguments - Why command line arguments are used - Quiz 7medium Memory Management Basics - Garbage collection overview - Quiz 11easy Methods and Code Reusability - Method overloading - Quiz 14medium Packages and Access Control - Why packages are used - Quiz 9hard Packages and Access Control - Default access modifier - Quiz 11easy Strings and String Handling - String creation - Quiz 12easy Strings and String Handling - String vs StringBuilder - Quiz 5medium Wrapper Classes - Unboxing - Quiz 1easy