Java daily practice (1)

Java daily practice (1)

radio part


1. In Java, objects storing string constants belong to ( ) class objects.

A Character B String C StringBuffer D Vector

Answer: B Review Article: String Class — Part _

2. Icon:

insert image description here


3. Among the following options, the main characteristics of object-oriented programming are ()

A: Inheritance B: Self-item C: Modularization D: Step-by-step refinement


Here are the three most basic features of object-oriented programming: encapsulation, inheritance, and polymorphism.

So the answer is obvious: A


4. Regarding the output results of the following program segments, the correct statement is: ( )

public class MyClass{
    
    
    static int i;
    public static void main(String argv[]){
    
    
    System.out.println(i);
    }
}

A: There is an error, the variable i is not initialized. B: null C: 1 D: 0


Here we mainly examine the definition of variables: In this way, the i we defined is assigned a value of 0 by default, so the answer is D. If we define a variable in the method without initialization, it will report an error if it is used directly.

5. The execution result of the following code is: ( )

public class Test{
    
    
        public static void main(String args[]){
    
    
            System.out.println(100%3);
            System.out.println(100%3.0);
        }
}

A: 1 and 1 B 1 and 1.0 C 1.0 and 1 D 1.0 and 1.0


This question is very simple: 100 % 3 == 1 , 100 % 3.0 == 1.0 So the answer is B

insert image description here


6. In the basic JAVA type, if not specified explicitly, the integer type defaults to the __ type, and the floating point number defaults to the __ type ()

A int float B int double C long float D long double


This question is also very simple, the default integer is int, and the floating point type is double.


Review the types in java:

Basic type:

Integer: byte , short , int , long Note: Their default value is 0

Character type: char Note: The default value is '\u0000'

Boolean type: boolean Note: The default value is false


Reference data type:

array, class, interface Note: The default value is null


Wrapper class:

Byte , Sort , Short , Integer , Long , Character ,Float , Double , Boolean

Note: String is not a wrapper class.

7. Which area in the process is the method usually stored in ()


A Heap area B Stack area C Global area D Method area


Method area (storage class, etc., the method belongs to the class, so the method is stored in the method area) Stack: the storage when the method is executed, the method execution process corresponds to the stack frame entering and exiting the stack, so the answer here is the D method area

.


8. Regardless of reflection, regarding the member variables modified by the private access control symbol private, the following statement is correct ()

A can be referenced by three classes: the class itself, other classes in the same package as it, and subclasses of this class in other packages

B can be accessed and referenced by two classes: the class itself, all subclasses of this class

C can only be accessed and modified by the class itself

D can only be accessed by classes in the same package

This question examines the access right qualifier, private: it is the keyword that realizes our encapsulation, and the member variable or member method modified by private cannot be used by other classes, so the answer is

C.

9. In the class declaration, the keyword to declare that a class can no longer be inherited is ()

A: public B: abstract C: final D: static


The class modified by final here cannot be inherited. Use C:

Inheritance


10. Suppose class A has the following definition, let a be an instance of class A, which of the following statements is wrong? ()

public class A
{
    
    
    public int i;
    static String s;
    void method1(){
    
    }
    static void method2(){
    
    }
}	

A : System.out.println(a.i);

B : a.method1();

C : A.method1();

D : A.method2();

Answer C here: Because method1 is not modified by static, it cannot be called directly through the class name.

programming questions


Topic 1: Team competition_Niu Ke pen test questions_Niu Ke.com (nowcoder.com)


Figure 1:

insert image description here


Figure II:

insert image description here


Figure 3: Code

insert image description here

This question is complete, let's continue:


2. Topic 2: Delete public characters

insert image description here

Guess you like

Origin blog.csdn.net/mu_tong_/article/details/127982027