Question: wwoWhen a runtime error occurs, an exception must be thrown so that the program can catch the exception and handle it or terminate the program.
wwoWhen a runtime error occurs, an exception must be thrown so that the program can catch the exception and handle it or terminate the program. Some exceptions such as ArrayIndexOutOfBoundsException are thrown by JVM. Your application can also throw an exception by creating an exception object and throwing it using keyword ________________. 2.Select all correct answers from the following descriptions of constructors. a. Every class has at least one constructor. If a class does not declare a constructor, the compiler provides a default constructor. b. A constructor can call another constructor in the same class by using keyword new. c. A class cannot have the same method name as the class name. d. this constructor call must be the first statement in a constructor. 3.Select all correct answers from the following descriptions of enum types. a. An enum type is a special type of class that can declare a set of constants. An enum class can have instance variables, constructors, and methods. b. You can create an object of an enum type by using keyword new. c. An enum type must be always declared as an inner class and cannot be declared as a separate file by itself. d. If an enum type has a String type instance variable, you can assign any string to an enum type variable. 4. Select the Java features and software engineering practices that apply the principle of least privilege. a. When the value of a variable must not change after being initialized, you can limit the possibility of inadvertent change of the value by declaring the variable final. b. Once the client classes of a class are implemented using the public instance variables of the class, it is very difficult to make any changes in the internal representation of the class, for example, changing data structures to provide more optimized efficient implementation, changing the variable names or types of the variables. Therefore, instance variables must be declared as private and only public methods that are not likely to change must be provided as public services. c. protected members of a class can be directly accessed from its subclasses, making the reuse of superclass easy. d. Declaring any variables as instance variables rather than local variables is recommended because it provides a way to easily extend an application in the future. 5. BigDecimal gives you control over how values are rounded. By default: a. all calculations are approximate and no rounding occurs. b. all calculations are approximate and rounding occurs. c. all calculations are exact and no rounding occurs. d. all calculations are exact and rounding occurs 6. A class can inherit from another class by using keyword ________________. The inheritance represents an is-a relationship, where a subclass of a class represents a more specialized concept than its superclass. 7. Keyword ________________ is used to call a constructor of a superclass or to call a method declared in the superclass, when the same name methods are declared in both the superclass and subclass. 8. Which of the following statements is false? a. Every class in Java, except class Object, extends an existing class. b. It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires. c. If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. d. To avoid duplicating code, we should use inheritance, rather than the copy-and-paste approach. 9. Which statement is true when a superclass has protected instance variables? a. A subclass object can assign an invalid value to the superclasss instance variables, thus leaving an object in an inconsistent state b. Subclass methods are more likely to be written so that they depend on the superclasss data implementation. c. We may need to modify all the subclasses of the superclass if the superclass implementation changes. d. All of the above. 10. Order the following access modifiers that control the accessibility (visibility) of methods and fields from other classes from the most accessible to the lease accessible. a. private b. no access modifier (package access) c. public d. protectedd
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
