Java - ArraysWhich of the following is a correct way to initialize an integer array with values 1, 2, 3 in Java?Aint[] arr = new int[3]{1, 2, 3};Bint arr[] = new int{1, 2, 3};Cint arr[] = {1, 2, 3};Dint[] arr = {1; 2; 3};Check Answer
Step-by-Step SolutionSolution:Step 1: Understand array initialization syntaxIn Java, you can initialize an array with values using curly braces without specifying size explicitly.Step 2: Check each optionint arr[] = {1, 2, 3}; uses correct syntax: int arr[] = {1, 2, 3}; int[] arr = new int[3]{1, 2, 3}; incorrectly combines size and initializer. int arr[] = new int{1, 2, 3}; misses brackets after new int. int[] arr = {1; 2; 3}; uses semicolons instead of commas.Final Answer:int arr[] = {1, 2, 3}; -> Option CQuick Check:Array initialization with values = int arr[] = {1, 2, 3}; [OK]Quick Trick: Use commas inside braces to list array values [OK]Common Mistakes:Mixing size declaration with initializer listUsing semicolons instead of commasOmitting square brackets after new keyword
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