7.8. Sample exam questions

Q7-1.

What is the output of the following code:

class Course {
    String courseName;
    Course() {
        Course c = new Course();
        c.courseName = "Oracle";
    }
}
class EJavaGuruPrivate {
    public static void main(String args[]) {
        Course c = new Course();
        c.courseName = "Java";
        System.out.println(c.courseName);
    }
}
  1. The code will print Java.
  2. The code will print Oracle.
  3. The code will not compile.
  4. The code will throw an exception or an error at runtime.

Q7-2.

Select the correct option(s):

  1. You cannot handle runtime exceptions.
  2. You should not handle errors.
  3. If a method throws a checked exception, it must be either handled by the method or specified in its throws clause.
  4. If a method throws a runtime exception, it may include the ...

Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.