Java Programming Final

25 July 2022
4.7 (114 reviews)
20 test answers

Unlock all answers in this set

Unlock answers (16)
question
__________ represents an entity in the real world that can be distinctly identified.
answer
Method
question
_______ is a construct that defines objects of the same type.
answer
A Class
question
An object is an instance of a __________.
answer
Class
question
The keyword __________ is required to declare a class.
answer
class
question
________ is invoked to create an object.
answer
A Constructor
question
Given the declaration Circle x = new Circle(), which of the following statement is most accurate. A. x contains an int value. B. x contains an object of the Circle type. C. x contains a reference to a Circle object. D. You can assign an int value to x.
answer
C.
question
The default value for data field of a boolean type, numeric type, object type is ___________, respectively. A. true, 1, Null B. false, 0, null C. true, 0, null D. true, 1, null E. false, 1, null
answer
B.
question
Analyze the following code: public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); } } A. The program has compile errors because the variable radius is not initialized. B. The program has a compile error because a constant PI is defined inside a method. C. The program has no compile errors but will get a runtime error because radius is not initialized. D. The program compiles and runs fine.
answer
A.
question
When invoking a method with an object argument, ___________ is passed. A. the contents of the object B. a copy of the object C. the reference of the object D. the object is copied, then the reference of the copied object
answer
C
question
You can declare two variables with the same name in __________. A. a method one as a formal parameter and the other as a local variable B. a block C. two nested blocks in a method (two nested blocks means one being inside the other) D. different methods in a class
answer
D
question
A Java exception is an instance of ________. Question options: A) NumberFormatException B) Throwable C) Exception D) RuntimeException E) Error
answer
B) Throwable
question
An instance of ________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program. Question options: A) Throwable B) RuntimeException C) Error D) Exception E) NumberFormatException
answer
D) Exception
question
An instance of ________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully. Question options: A) Throwable B) RuntimeException C) NumberFormatException D) Error E) Exception
answer
D) Error
question
Which of the following is not an advantage of Java exception handling? Question options: A) Exception handling makes it possible for the caller's caller to handle the exception. B) Exception handling simplifies programming because the error-reporting and error-handling code can be placed at the catch block. C) Exception handling improves performance. D) Java separates exception handling from normal processing tasks.
answer
C) Exception handling improved performance
question
What is displayed on the console when running the following program? class Test { public static void main(String[ ] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question options: A) The program displays Welcome to Java three times followed by End of the block. B) The program displays Welcome to Java two times. C) The program displays Welcome to Java three times. D) The program displays Welcome to Java two times followed by End of the block.
answer
D) The program displays Welcome to Java two times followed by End of the block.
question
What is displayed on the console when running the following program? class Test { public static void main (String[ ] args) { try { System.out.println("Welcome to Java"); } finally { System.out.println("The finally clause is executed"); } } } Question options: A) Welcome to Java followed by The finally clause is executed in the next line B) The finally clause is executed C) Welcome to Java D) None of the above
answer
A) Welcome to Java followed by The finally clause is executed in the next line
question
What is wrong in the following program? class Test { public static void main (String[ ] args) { try { System.out.println("Welcome to Java"); } } } Question options: A) Nothing is wrong. B) A method call that does not declare exceptions cannot be placed inside a try block. C) You cannot have a try block without a catch block or a finally block. D) You cannot have a try block without a catch block.
answer
C) You cannot have a try block without a catch block or a finally block.
question
A method must declare to throw ________. Question options: A) Error B) unchecked exceptions C) checked exceptions D) RuntimeException
answer
C) checked exceptions
question
What exception type does the following program throw? public class Test { public static void main(String[ ] args) { int[ ] list = new int[5]; System.out.println(list[5]); } } Question options: A) ArrayIndexOutOfBoundsException B) No exception C) ArithmeticException D) StringIndexOutOfBoundsException E) ClassCastException
answer
A) ArrayIndexOutOfBoundsException
question
What exception type does the following program throw? public class Test { public static void main(String[ ] args) { System.out.println(1 / 0); } } Question options: A) StringIndexOutOfBoundsException B) ClassCastException C) ArithmeticException D) No exception E) ArrayIndexOutOfBoundsException
answer
C) ArithmeticException