170k views
5 votes
What code would you use to tell if "schwifty" is of type String?

a. "schwifty".getClass().getSimpleName() == "String"
"b. schwifty".getType().equals("String")
c. "schwifty".getType() == String
d. "schwifty" instanceof String

User Waylander
by
8.2k points

1 Answer

5 votes

Answer:

d. "schwifty" instanceof String

Step-by-step explanation:

Given

List of options

Required

Determine which answers the question.

The syntax to check an object type in Java is:

[variable/value] instanceof [variable-type]

Comparing this syntax to the list of options;

Option d. "schwifty" instanceof String matches the syntax

Hence;

Option d answers the question

User Man
by
7.6k points