Java daily exercises, make progress every day (8)


Thanks for your love, we make progress together every day! (click the blank space to view the answer)

1. This represents the object reference of (), and super represents the () object of the current object?

Correct answer: C

Current class current class

Parent class of current class current class

Current class parent of current class

None of the above is correct

This represents the current object, that is, the reference of the object of the current class
Super represents its parent class object

2. The output content is:

public static void main(String[] args) {
Thread t = new Thread() {
public void run() {
static void my360DW() {

Correct answer: C




No output

The purpose of this topic is to examine the difference between the method t.start() to start a thread and the direct call However, there is no note in the title: the run () method that directly calls the thread will either start the thread or call it normally. It will directly execute the contents of the run () method

3. The output of the following program is: ()

String x="fmn";
String y=x.replace('f','F');

Correct answer: D





String x=“fmn”; “FMN” is an immutable object in the constant pool.
x.toUpperCase(); New an “FMN” object in the heap, but no reference points to it.
String y=x.replace(‘f’,‘F’); New an “FMN” object in the heap, and Y points to it.
y=y+“wxy”; Create a new “fmnwxy” object in the heap, modify the Y point, and now y points to it.

4. The output of executing the following code is ()

public class Demo{
 public static void main(String args[]){
   int num = 10;
public static int test(int b){
    b += 10;
    return b;
   catch(RuntimeException e)
   catch(Exception e2)
    b += 10;
    return b;

Correct answer: C





If there is a return statement in the finally block, it will overwrite other return statements in the function. So it’s 30

5. What is the output of the following code?

public class ZeroTest {
    public static void main(String[] args) {
       int i = 100 / 0;
  }catch(Exception e){
       throw new RuntimeException();

Correct answer: D





1、inti = 100/ 0; An exception will occur and an exception will be thrown. System out. Print (I) will not be executed,
2. Catch catch exception and continue to execute system out. print(1);
3. When thrownewruntimeexception() is executed; An exception will be thrown again. At this time, except for the code in finally, the code in other places will not be executed. Therefore, after executing the finally statement block, the program terminates

6、Math.floor(-8.5)=( )

Correct answer: D





Math. Floor (x) returns the nearest integer less than or equal to x, and the type is double
Math. Floor() indicates rounding down and returns double type (floor – floor)
Math. Ceil() indicates rounding up and returns the double type (ceil – ceiling)
Math. Round() round, return int type

7、ArrayList list = new ArrayList(20); The list in is expanded several times

Correct answer: a





The default array size of ArrayList is 10. The size after resizing is 1.5 times that before resizing. The maximum value is less than the maximum value of integer minus 8. If the newly created collection has an initial value, the default is the size passed in, and the resizing will not be performed

8. The output of the following code segment after execution is

public class Test {
public static void main(String args[]) {
int i = -5;
i =  ++(i++);

Correct answer: C



Compilation error


The answer is a compilation error.
The compilation error lies in this sentence: I = + + (i++);
++() there must be a variable in the bracket, and I ++ is a literal.

9. If you need to define a class, which of the following modifiers are allowed? ( )

Correct answer: a C D





Common class (external class): can only be decorated with public, default (do not write), abstract and final.
(member) internal class: it can be understood as a member of an external class, so public, protected, default, private, static and other keywords that modify class members can be used.
Local internal class: a class that appears in a method and cannot be modified with the above keywords.
Anonymous inner class: it is given a direct implementation. There is no class name and no modifier.

10. The life cycle of a servlet can be divided into three stages: initialization stage, operation stage and destruction stage. The following processes belong to the initialization stage: Yes ().

Correct answer: a C D

Load servlet classes and Data corresponding to class

Create ServletRequest and servletresponse objects

Create a ServletConfig object

Create servlet object

The life cycle of a servlet can generally be expressed in three ways:
Init(): it is executed only once and is responsible for initializing the servlet object when loading the servlet
Service (): the core method. Generally, there are two processing methods in httpservlet: get and post. When calling doget and dopost methods, ServletRequest and servletresponse request and response objects will be constructed as parameters.
Destroy (): it is executed when the servlet is stopped and unloaded. It is responsible for releasing resources
Initialization phase: when the servlet starts, it will read the information in the configuration file, construct the specified servlet object, create the ServletConfig object, and call the init() method with ServletConfig as a parameter. So choose ACD. B is constructed when the service method is called

Answer summary:

1. Correct answer: C

2. Correct answer: C

3. Correct answer: D

4. Correct answer: C

5. Correct answer: D

6. Correct answer: D

7. Correct answer: a

8. Correct answer: C

9. Correct answer: a C D

10. Correct answer: a C D


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

Recommended Today

Objective-C of IOS learning notes (II)

Previous article At the end, a demo is sketched out: define a student class, instantiate a Xiaoming object, and implement them using python, Java and Objective-C at the same time. This code only demonstrates some of the most basic OC syntax, but it also leaves a few questions that are difficult for beginners to understand: […]