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. StringConceptJava separates its built-in primitive value types from reference types. Primitive variables directly hold values in one of eight language-defined…

  1. A.

    boolean

  2. B.

    byte

  3. C.

    double

  4. 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.

Explore the full course: Uppsc Computer Operator Grade B

Loading lesson…