Which of the following is the correct syntax to declare a primitive int and a reference String in Java?
easy📝 Syntax Q3 of 15
Java - Memory Management Basics
Which of the following is the correct syntax to declare a primitive int and a reference String in Java?
Aint number = new int(5); String text = "Hello";
Bint number = 5; String text = new String("Hello");
Cint number = new int(5); String text = new String(Hello);
Dint number = Integer(5); String text = "Hello";
Step-by-Step Solution
Solution:
Step 1: Declare primitive int
Primitive int is declared simply as int number = 5; no new keyword needed.
Step 2: Declare reference String
String is a reference type; it can be assigned directly or with new String("Hello"). int number = 5; String text = new String("Hello"); uses new String("Hello") correctly.
Final Answer:
int number = 5; String text = new String("Hello"); -> Option B
Quick Check:
Primitive int direct, String reference with new [OK]
Quick Trick:Primitive types no new; reference types can use new [OK]
Common Mistakes:
Using new keyword with primitives
Incorrect String constructor usage
Master "Memory Management Basics" in Java
9 interactive learning modes - each teaches the same concept differently