[School Recruitment VIP] Java language test center switch and default

Introduction to test points:
switch and default are one of the keyword combinations often tested during interviews for Java positions in school recruitment.

Java language test points - switch and default - related questions and analysis content can be viewed by clicking the link at the end of the article!

1. Test questions

1. Can the switch statement operate on byte, long, or String?
Answer: In switch (e), e can only be an integer expression or an enumeration constant (larger font ), the integer expression can be of int primitive type or Integer wrapper type...

2. In the following switch statement, what types of data can x be: ()

1

2

3

4

5

1 switch(x)

2 {

3 default:

4 System.out.println("Hello");

5 }

A.long
B.char
C.float
D.byte

Answer: The correct answers are B and D. Based on Java 8, switch supports 10 types.
Basic type: byte char short int...

3. In the description of the switch statement, the correct one is ()
A. There can be no default clause in the switch statement, or there can be one
. B. There must be a break statement in each case statement sequence in the switch statement
. C. Default clause in the switch statement. The clause can only be placed at the end.
The expression after the case clause in the switch statement can only be an integer expression.

Answer: The correct answer is that A switch statement may have no or one default clause; each case statement sequence may or may not have a break statement...

4. Let’s talk about
the answer to the default keyword: added since Java 8
, it is used to modify methods so that methods in the interface can be written into the method body...

2. Examination articles

1. How to use default in switch.
When will default be executed? Does the position of default affect the execution results? default will only be executed when case matching fails...

2. Analysis of the use of default in the Java switch statement switch.
When studying "Thinking in Java" 7.2.2, I saw a strange usage of default in a switch statement, so I decided to study this ridiculous operation...

3. Precautions for switch in Java and the relationship between break and default
1. Switch() must be of character type or integer type
2. After case, it can be a constant or a constant expression, but there cannot be variables...

3. Test point video

Static Keyword Novel
The static keyword can be understood as "shared" and "global unique", which can be used to simply examine the usage scenarios of this keyword, and can also be further extended to concurrency security and singleton mode. It is a pen test with 5 sides and 5 test points and must be prepared

Java language test center switch and default-related questions and analysis content can be viewed by clicking on the link below:
Java language test center switch and default-mobile link
Java language test center switch and default-PC link

Guess you like

Origin blog.csdn.net/shuize123/article/details/132967953