full stack dev quiz

Full-stack dev quiz question #56

Full-stack dev quiz question #56quiz

Construtors in Java have limitations. Not everything is possible in them. Check fifty sixth question of full-stack dev quiz to check if you know what they are.

This is a code of one class in Java 11. It has a serious issue that prevents it from being usable. Actually, it will not even compile.

public class AppException extends Exception {

public AppException(int errorCode, Throwable cause) {
if (errorCode == 1) {
} else {
super(buildMessage(errorCode), cause);

private static String buildMessage(int errorCode) {
switch (errorCode) {
case 1:
return "User not found";
case 2:
return "Malformed request";
return "Unknown error";


What is the compilation-time problem with that class? Choose the best answer.

  1. Exception class cannot be extended as it is final.
  2. AppException constructor must have the same list of arguments as a construction from Exception class.
  3. Calling the super constructor cannot be precedented by any other code.
  4. A constructor cannot call a static method.
  5. A switch statement cannot return String.

For the correct answer scroll down













Do not miss valuable content. You will receive a monthly summary email. You can unsubscribe anytime.

















The correct answer is: c. If you would like to read more, check Logic in constructor or static factory method article.

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.