Java daily exercises, make progress a little every day (23)


Thanks for your love, we make progress together every day! (check the blank space with the mouse to see the answer)

1. What will the following program output

int a =100,b=50,c=a---b,d=a---b;

Correct answer: C

100 48 48 49

100 49 48 52

98 50 50 49

98 50 50 48

The priority of self increasing and self decreasing operators is higher than that of addition and subtraction operators
C = a — B, first execute A-B operation to get C = 50, and then execute a minus 1 operation to get a = 99, and B remains unchanged.
D = a — B, first execute A-B operation to get d = 49, and then execute a minus 1 operation to get a = 98, B unchanged.

2. The following description of the selection statement is wrong ()

Correct answer: a

Execute part of the code repeatedly according to a certain condition until the termination condition is met

The program flow can be controlled according to conditions and the sequence of program execution can be changed

Selection statements can be nested

When the condition is met, the corresponding statement will be executed

A the answer is a circular statement
Four types of flow control statements in Java
Circular statements: while, for, do while
Select statement (branch statement): if, switch
Jump statements: break, continue, break, label
Exception handling statement: try catch finally, throw

3. The following description of Java is correct ()

Correct answer: a

The modification method of table name of native keyword is written by other non java languages

Only comment statements can appear before import statements

Methods defined in the interface can only be public

Constructor can only be modified as public or default

A: Native refers to calling local method libraries (such as the underlying functions of the operating system), which can be implemented by C and C + +, and a is correct
B: Import is a package import statement, which can be preceded by package to declare package B errors
C: The modifiers of interface methods can be: public, abstract, default, static (the latter two need to have {}), and C is correct
D: The constructor can use private, protected, default, private, D error

4. 8-bit binary complement composed of 3 “1” and 5 “0”, the smallest integer that can be represented ()

Correct answer: B





Since the minimum integer is calculated, the negative number must be thought of first. Then the highest bit (sign bit) must be 1. The higher the number of bits of 1 in the original code, the smaller the value. While the complement is obtained by adding 1 inversely to the original code, the lower the number of bits of 1 in the complement, that is, the complement is 1000 0011; Get the original code from the complement: 1111 1101 = – (64 + 32 + 16 + 8 + 4 + 1) = – 125

5. Look at the following code:

File name: forward jsp

     < head > < title > jump to < / Title > < / head > 
         <jsp:forward page="index.htm"/>     

If you run the above JSP file, the content of the address bar is

Correct answer: a

6. Which of the following options is a legal Identifier? ()

Correct answer: B D





1. It can only be composed of numbers, letters and symbols (there are only and $).
2. The number cannot be used as the beginning of the identifier.
3. It cannot be the same as keywords, reserved words and explicit constants. Keywords are lowercase.
4. Null, true and false are not keywords and belong to explicit constants. Goto and const are reserved keywords.

7. In the following expression, the correct is ()

Correct answer: C D

byte i=128

boolean i=null

long i=0xfffL

double i=0.9239d

A byte, 1 byte, range – 128 to 127
B Boolean is not a wrapper object and cannot be assigned null

8、jdk1. Before version 8, the correct descriptions of interfaces and abstract classes are ()

Correct answer: B C

Abstract classes do not have constructors

Interface has no constructor

Abstract classes do not allow multiple inheritance

A method in an interface can have a method body

Abstract classes can have constructors, but they cannot be instantiated
jdk1. Methods modified with static or default in the interface after 8 can have method bodies

9. The following can get the result set correctly:

Correct answer: a D

A:Statement sta=con.createStatement();

ResultSet rst=sta.executeQuery(“select * from book”);

B:Statement sta=con.createStatement(“select * from book”); ResultSet rst=sta.executeQuery();

C:PreparedStatement pst=con.prepareStatement();

ResultSet rst=pst.executeQuery(“select * from book”);

D:PreparedStatement pst=con.prepareStatement(“select * from book”);

ResultSet rst=pst.executeQuery();

A. D is correct; Creating a statement does not pass parameters. Preparedstatement needs to pass in SQL statements

10. Is the following statement correct ()?

Correct answer: a B

A: For local inner classes, inner classes can use methods only if their local variables are marked final or if they are effctively final

B: The inner class of the member is located inside the outer class and can directly call all methods (static and non static methods) of the outer class

C: Because anonymous inner classes can only be used inside methods, the usage of anonymous inner classes is consistent with that of local inner classes

D: Static inner classes can directly access non static members of external classes

A. Right.
B. Right.
C. Wrong. The usage of anonymous inner class is different from that of local inner class. Firstly, the definition is different. Anonymous class is used wherever expressions are allowed, while local inner class is used wherever local variables are allowed.
More importantly, anonymous classes can only be used once, while local classes can be used multiple times in their own domain.
D. Wrong. Static inner classes cannot directly access non static members of external classes, but they can use new outer class () Member access

Answer summary:

1. Correct answer: C

2. Correct answer: a

3. Correct answer: a

4. Correct answer: B

5. Correct answer: a

6. Correct answer: B D

7. Correct answer: C D

8. Correct answer: B C

9. Correct answer: a D

10. Correct answer: a B


That’s all for this article. I hope it can help you, and I hope you can pay more attention to more content of developeppaer!