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 {/* Implementation not shown */}
Key.java
public class Key {/* Implementation not shown */}
Potion.java
public class Potion {/* Implementation not shown */}
Item.java
public class Item { public Item() {} }
Main.java
public class Main { public static void main(String[] args) { Item armor = new Armor(); Item key = new Key(); Item potion = new Potion(); } }
Why does this code not compile?
This code does compile
Subclasses don’t have constructors
Subclasses don’t extend Item
Item
Item class constructor is empty
Subclasses are public