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:
ParentClass.java
public class ParentClass { String name; public ParentClass(String name) { this.name = "hello"; } }
ChildClass.java
public class ChildClass extends ParentClass { String name; public ChildClass(String name) { super(name); this.name = name; } public void print() { System.out.println("super.name: " + super.name); System.out.println("this.name: " + this.name); } }
Main.java
public class Main { public static void main(String[] args) { ChildClass child = new ChildClass("world"); child.print(); } }
What does this program do?
prints to the console:
super.name: world this.name: world
super.name: hello this.name: world
super.name: hello this.name: hello
Compile error
Runtime error