Prev Next

Quiz - 5

This quiz tests your knowledge of Java language semantics. Get a print out of this when you come to the class.

  • First try answering without running the program.
  • Then run the program to check if your understanding was indeed correct.
  • Enter both the answers in the last column and submit.
Concept Program Your answer first, followed by the actual answer
Defining
custom
checked
exception
// CheckedException.java
public class CheckedException extends Exception {
  public CheckedException(String s) {
    super(s);
  }
}
Defining
custom
unchecked
exception
// UncheckedException.java
public class UncheckedException 
                    extends RuntimeException {
  public UncheckedException(String s) {
    super(s);
  }
}
Throwing
Exception:
checked or
unchecked
// AThrow.java
public class AThrow {
  private int weight;
  public AThrow(int w) throws CheckedException {
                       // or UncheckedException
  	if (w > 0)
      weight = w;
    else
      throw new AException("Every object has mass!");
  }
}