Repaso
EspaƱol
Java CoreFoundationsJV-48

What does this code do?

int age = 30;
String name = "Ana";

Options

  1. Declares an int holding 30 and a String holding Ana (Correct option)
  2. Compares age with 30 and stores the result in name
  3. Creates two new classes that are called age and name
  4. Imports two packages that are called age and name

Answer

Declares two variables with their types: an int (whole number) holding 30 and a String (text) holding Ana

Why

Java is statically typed: every variable must have a declared type before you use it. int is a whole number, String is text, double a decimal number and boolean true or false.

A semicolon ; ends each statement. Text goes in double quotes.

You cannot put text into an int variable: the compiler rejects it, which catches mistakes before running.

Remember

Java: declare the type, then the name, then the value.

Key terms

Practice this question in Repaso