In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "sample analysis of Java object-oriented choice questions", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and study the "sample analysis of Java object-oriented choice questions".
1. The execution of the following procedures is incorrect (ABC)
Public class MultiCatch {public static void main (String args []) {try {int astatargs.cards; int bread42 xantha; / 10 lines int c [] = {1}; c [42] = 99; System.out.println ("b =" + b);} catch (ArithmeticException e) {System.out.println ("except 0 exception:" + e) / / 15 line} catch (ArrayIndexOutOfBoundsException e) {System.out.println ("Array beyond boundary exception:" + e); / / 19 line}
A. the program will output the exception information on line 15
B. error in line 10 of the program
C. The program will output "baked 42".
D. the program will output the exception information on line 15 or 19.
Note: first analyze option A, it says that line 15 will output abnormal information, then let's take a look at the whole program, int a = args.length this sentence is to get the length of the args array, this place may not be clear, many people think that it is empty, that is, the length is 0, then it will definitely throw an exception, but in fact, this array in this main can be assigned (here you can Baidu) This assignment is very special, so An is wrong and does not necessarily throw an exception.
The same is true of B.
Let's see C, the program will output "bread42". Obviously, if the args array is really 0, he will skip System.out.println ("b =" + b); go straight into the catch statement and throw an exception, so it doesn't necessarily output 42.
Look at D, the program will output 15 or 19 lines of exception information, it is obvious that the array out of bounds will be 100% error, but there will not necessarily be divided by 0 exception, so D pair.
two。 What is the return value of this method (B)
Public static int divide () {int I = 3; try {int a = 10 + 0; return I;} catch (Exception e) {I = 4; return I;} finally {I = 5;}}
A.3
B.4
C.5
d. Report an abnormal error
Analysis: this question is indeed a bit of a pit, but return mastery is completely no problem, I believe that most of the candidates C, but the actual answer is B. We first analyze step by step, first of all, the try will definitely throw an exception, so when it comes to int a = 10\ 0, we jump directly into the catch statement, when I is assigned to 4, and return returns I value, we all know that the finally statement will be executed at last, but we return I in catch, any other assignment is useless!
So choose B.
three. Which of the following is true for the arrangement of catch clauses (B)
A. The parent class comes first and the child class comes after.
B. the subclass comes first, and the parent class comes after.
C. Exceptions with inheritance cannot be in the same try segment
D, there are subclasses first, but it doesn't matter how the others are arranged.
Analysis: let me give you two
Like the one at the bottom, it's okay.
Public class MultiCatch {public static void main (String args []) {try {. } catch (ArithmeticException e) {/ / subclass exception System.out.println ("divided by 0 exception:" + e);} catch (Exception e) {System.out.println ("exception:" + e); / / parent exception}} is omitted here
It doesn't work like the one below, and the reward is wrong, because Exception is a very large class, and basically all exceptions are inherited from it, and with it, you can handle all exceptions, so what you write later is meaningless, so it's wrong.
Public class MultiCatch {public static void main (String args []) {try {. Omit} catch (Exception e) {/ / parent exception System.out.println ("exception:" + e);} catch (ArithmeticException e) {System.out.println ("divide 0 exception:" + e); / / subclass exception} above is all the content of the article "sample Analysis of Java object-oriented Choice questions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.