Java - ArraysWhich of the following is a valid way to declare an array and get its length in Java?Aint[] arr = new int[5]; int len = arr.length;Bint arr[] = new int(5); int len = arr.length();Cint arr[] = new int[5]; int len = arr.size();Dint arr = new int[5]; int len = arr.length;Check Answer
Step-by-Step SolutionSolution:Step 1: Check array declaration syntaxCorrect array declaration uses square brackets and new int[5] to allocate size.Step 2: Check length access syntaxLength is accessed as a property without parentheses: arr.length.Final Answer:int[] arr = new int[5]; int len = arr.length; -> Option AQuick Check:Array declared with [] and length accessed as property [OK]Quick Trick: Declare arrays with [] and use .length property [OK]Common Mistakes:Using parentheses in new int(5)Calling length() as a methodUsing size() method on arraysDeclaring array without []
Master "Arrays" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Command Line Arguments - Syntax for command line arguments - Quiz 10hard Command Line Arguments - Why command line arguments are used - Quiz 13medium Memory Management Basics - Garbage collection overview - Quiz 13medium Packages and Access Control - Private access modifier - Quiz 4medium Packages and Access Control - Public access modifier - Quiz 10hard Packages and Access Control - Protected access modifier - Quiz 7medium Packages and Access Control - Public access modifier - Quiz 11easy Static Keyword - Static variables - Quiz 7medium Strings and String Handling - String comparison - Quiz 2easy Strings and String Handling - String comparison - Quiz 5medium