Java Questions 20. Within the body of a method named myMethod, there is a call t
ID: 3719081 • Letter: J
Question
Java Questions
20. Within the body of a method named myMethod, there is a call to another method that may throw a checked exception. What are the two options the programmer has to ensure that myMethod will compile?
22. What is the OO concept that means the functionality of one class can be extended over overridden in another class?
23. Which statement displays the contents of a variable named message, moving the cursor to the next line?
a. System.out.println("message");
b. System.out.println(message);
c. System.out.printf("%s", message);
d. System.out.print(message);
e. System.out.printf("%s%n", "message");
Use the following code to answer questions 24 and 25.
public static void main(String[] args) {
int i = 0;
do {
if (++i % 5 == 0)
System.out.print(i + " ");
} while (i < 20);
}
24. How many times is the body of the loop repeated?
25. What is the exact output of the code?
Explanation / Answer
20. Within the body of a method named myMethod, there is a call to another method that may throw a checked exception. What are the two options the programmer has to ensure that myMethod will compile?
Answer:
1. by using try - catch block
2. by using throws clause at method header
22. What is the OO concept that means the functionality of one class can be extended over overridden in another class?
Answer:
Polymorphism
23. Which statement displays the contents of a variable named message, moving the cursor to the next line?
Answer:
b. System.out.println(message);
24. How many times is the body of the loop repeated?
Answer:
20 times
25. What is the exact output of the code?
Answer:
5 10 15 20
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.