Question: QUESTION 1 Examine the following code. What output is produced? class Test { public static void main(String[] args) { try { myMethod(); System.out.println(After the method

QUESTION 1

  1. Examine the following code. What output is produced?

    class Test { public static void main(String[] args) { try { myMethod(); System.out.println("After the method call"); } catch (NumberFormatException ex) { System.out.println("NumberFormatException"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } } static void myMethod() { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } }
    A.

    NumberFormatException and then after the method call.

    B.

    NumberFormatException and then RuntimeException.

    C.
    NumberFormatException
    D.

    The program will not compile.

10 points

QUESTION 2

  1. What type of exception will be thrown by the following code?

    public class Test { public static void main( String[] args ) { System.out.println(1 / 0); } }
    A.

    An ArithmeticException.

    B.

    No exception will be thrown.

    C.

    An ArrayIndexOutOfBoundsException.

    D.

    A ClassCastException.

10 points

QUESTION 3

  1. What type of exception must be advertised in a method declaration?

    Errors.

    Checked exceptions.

    Runtime exceptions.

    Unchecked exceptions.

10 points

QUESTION 4

  1. Which of the following statements about the Java language are true?

    1. You can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism.
    2. The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compilation time.
    3. A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime.
    4. Dynamic binding can apply to static methods.
    5. Dynamic binding can apply to instance methods.
    A.

    All of the answers.

    B.

    Answers 1, 2, and 5 only.

    C.

    Answers 1, 2, 3, and 5 only.

    D.

    Answers 1, 2, 3, and 4 only.

10 points

QUESTION 5

  1. Consider the following code. What output is produced when it is run?

    public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { private String getInfo() { return "Student"; } } class Person { private String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } }
    A.
    Student Person
    B.
    Student Student
    C.
    Person Person
    D.
    Person Student

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!