Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
Given:
Armor.java
public class Armor extends Item { public void use() {/* Implementation not shown */} }
Key.java
public class Key extends Item { public void use() {/* Implementation not shown */} }
Potion.java
public class Potion extends Item { public void use() {/* Implementation not shown */} }
Item.java
public class Item { public Item() {/* Implementation not shown */} }
Main.java
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Item> items = new ArrayList<Item>(); items.add(new Armor()); items.add(new Key()); items.add(new Potion()); for (Item item : items) { item.use(); } } }
What will this program do?
Runtime error during loop
Compile Error
Run to completion
Infinite loop
Runtime error adding items to list