A program declares a String variable but never makes it refer to an actual String object before using it:


Java
String name = null;
int n = name.length();
System.out.println(n);


What happens when this code is compiled and run?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A warehouse program represents each robot as a software object. One robot currently has a battery level of 72% and a location of aisle 4. It can report its location and move to another aisle.


Complete each sentence using either state or behavior. You may use a word more than once.


The robot object's current battery level and location describe its .


The actions that the robot object can perform describe its .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

The following Java code creates a String object and calls several of its methods, storing each returned value in a variable:


Java
String city = "Saskatoon";
int len = city.length();
String part = city.substring(2, 5);
int pos = city.indexOf("o");
String shout = part.toUpperCase();


After all five lines run, give the value of each variable. Enter len and pos as exact integers. Enter part and shout exactly as Java stores them, with correct capitalization and without quotation marks.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors