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
-
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
-
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
-
What type of exception must be advertised in a method declaration?
Errors.
Checked exceptions.
Runtime exceptions.
Unchecked exceptions.
10 points
QUESTION 4
-
Which of the following statements about the Java language are true?
- You can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism.
- The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compilation time.
- A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime.
- Dynamic binding can apply to static methods.
- 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
-
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
Get step-by-step solutions from verified subject matter experts
