Java - Strings and String HandlingWhich of the following is the correct way to create a string variable in Java?AString greeting = "Hello";Bstring greeting = 'Hello';CString greeting = Hello;DString greeting = "Hello"Check Answer
Step-by-Step SolutionSolution:Step 1: Check the data type and quotesJava strings use the class String with a capital S and text must be in double quotes.Step 2: Validate syntax correctnessString greeting = "Hello"; uses correct capitalization, double quotes, and ends with a semicolon.Final Answer:String greeting = "Hello"; -> Option AQuick Check:String creation uses String and double quotes [OK]Quick Trick: Use capital S in String and double quotes for text [OK]Common Mistakes:Using single quotes instead of double quotesUsing lowercase 'string' instead of 'String'Missing semicolon at the end
Master "Strings and String Handling" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Arrays - Why arrays are needed - Quiz 12easy Arrays - Array declaration and initialization - Quiz 4medium Arrays - Array declaration and initialization - Quiz 12easy Command Line Arguments - Accessing arguments - Quiz 4medium Command Line Arguments - Use cases - Quiz 9hard Memory Management Basics - Heap memory - Quiz 14medium Packages and Access Control - Public access modifier - Quiz 12easy Static Keyword - Static vs non-static behavior - Quiz 6medium Static Keyword - Static methods - Quiz 1easy Wrapper Classes - Primitive to object conversion - Quiz 6medium