Question #7 for Java Classes Quiz

Question: Why will the following program produce an error?

public Shelf {

  String material;
  
  public Shelf() {
  
  }
  
  public static void main(String[] args) {
    Shelf bureau = new Shelf("pine");
  }
}

Answer: The constructor does not have a parameter listed.

But should "public Shelf " at the top include “class” as in “public class Shelf”?

I got this question wrong. below is the link.

Is it not necessary to add “class”? This question seems to suggest so.

https://www.codecademy.com/courses/learn-java/quizzes/intro-to-java-classes-qz?action=resume_content_item

2 Likes

I believe you are correct. This would appear to be an oversight on the part of the quiz writer. The correct answer is still correct, but the error for leaving out ‘class’ would be raised first.