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
1.// CheckedException.java
2.public class CheckedException extends Exception {
3.  public CheckedException(String s) {
4.    super(s);
5.  }
6.}
Defining
custom
unchecked
exception
1.// UncheckedException.java
2.public class UncheckedException
3.                    extends RuntimeException {
4.  public UncheckedException(String s) {
5.    super(s);
6.  }
7.}
Throwing
Exception:
checked or
unchecked
01.// AThrow.java
02.public class AThrow {
03.  private int weight;
04.  public AThrow(int w) throws CheckedException {
05.                       // or UncheckedException
06.    if (w > 0)
07.      weight = w;
08.    else
09.      throw new AException("Every object has mass!");
10.  }
11.}
1. 
1. 
1. 
1. 
1. 
1. 
1. 
1. 
1. 
1.