Which of the following is NOT a primitive data type in Java?
2021
Which of the following is NOT a primitive data type in Java?
Answer: D. String — ConceptJava separates its built-in primitive value types from reference types. Primitive variables directly hold values in one of eight language-defined…
- A.
boolean
- B.
byte
- C.
double
- D.
String
Attempted by 2 students.
Show answer & explanation
Correct answer: D
Concept
Java separates its built-in primitive value types from reference types. Primitive variables directly hold values in one of eight language-defined categories: byte, short, int, long, float, double, char, and boolean.
Class types such as String are reference types: their variables refer to objects rather than belonging to the primitive set.
Application
Classify each offered value by that definition:
boolean belongs to the primitive set and represents the truth values true and false.
byte belongs to the primitive set and represents an 8-bit signed integral value.
double belongs to the primitive set and represents a 64-bit floating-point value.
String is a class in java.lang, so a String variable is a reference to an object.
Cross-check
The Java Language Specification lists boolean and the numeric types, including byte and double, as primitive types; String is declared as a class rather than included in that list.
Result
Therefore, String is the value that is not a primitive data type in Java.