1. Can objects be created without using a constructor? ()
A. Yes (Recommended study: Summary of java interview questions)
B. No
Analysis: Answer: A
Several ways to create objects in Java (important) :
(1) Use the new statement to create an object. This is the most common method of creating an object.
(2) Use reflection to call the newInstance() instance method of the java.lang.Class or
java.lang.reflect.Constructor class.
(3) Call the clone() method of the object
(4) Use deserialization method to call the readObject() method of the java.io.ObjectInputStream object.
(1) and (2) will explicitly call the constructor; (3) is a copy of the existing object in the memory, so the constructor will not be called; (4) is from the file The object of the class is restored and the constructor is not called.
(1) and (2) will explicitly call the constructor; (3) is a copy of the existing object in the memory, so the constructor will not be called; (4) is from the file The object of the class is restored and the constructor is not called.
2. Which of the following are symmetric encryption algorithms ()
A. DES
#B. MD5
C. DSA
D. RSA
Analysis: Answer: A
Analysis: Commonly used symmetric encryption algorithms are: DES, 3DES, RC2, RC4, AES
Commonly used asymmetric encryption algorithms are: RSA, DSA, ECC
Encryption algorithms using one-way hash functions: MD5, SHA
3. The following code segment, when the input is 2, the return value is ()
public static int get Value(int i){ int result=0; switch(i){ case 1: result=result +i case 2: result=result+i*2 case 3: result=result+i*3 } return result; }
A. 0
B. 2
C. 4
D. 10
Answer: C
Analysis: result = 0 2 * 2;
4. The following Java code snippet will produce several An object
public void test(){ String a="a"; String b="b"; String c="c"; c=a+""+b+""+c; System.out.print(c); }
Analysis: Answer: An object, because of optimization during compilation, three string constants are directly collapsed into one
5.Math.round( -11.2) The running result is.
Answer: -11
Analysis: The first decimal place=5
Positive numbers: Math.round(11.5)=12
Negative numbers: Math.round(-11.5)=-11
The first decimal place<5
Positive numbers: Math.round(11.46)=11
Negative numbers: Math.round(-11.46)=-11
First decimal place>5
Positive numbers: Math.round(11.68)=12
Negative numbers :Math.round(-11.68)=-12
According to the running results of the above example, we can also summarize it as follows, which may be easier to remember:
The first decimal place of the parameter <5, the operation result is the integer part of the parameter.
The first digit after the decimal point of the parameter is >5, and the operation result is the absolute value of the integer part of the parameter, 1, and the sign (i.e., positive or negative) remains unchanged.
The first digit after the decimal point of the parameter = 5, the result of a positive number operation is the integer part 1, and the result of a negative number operation is the integer part.
End: Add all positive numbers greater than five, add all positive numbers equal to five, and do not add any positive numbers less than five.
6. The number of bytes occupied by int.long in Java are
Analysis:
1: "Word Section" is byte, "bit" is bit;
2: 1 byte = 8 bit;
char is 2 bytes in Java. Java uses Unicode, 2 bytes (16 bits) to represent a character.
short 2 bytes
int 4 bytes
long 8 bytes
System.out.println('a' 1) The result of ; is
Analysis: 'a' is a char type, 1 is an int row, int and char are added, char will be forcibly converted to an int row, and the corresponding value of the ASCII code of char is 97, so Together they print 98
7. Which of the following statements is correct ()
A. After the java program is compiled, machine code
B will be generated. After the java program is compiled, it will generate byte code
C. After the java program is compiled, it will generate DLL
D. None of the above is correct
Answer: B
Analysis: After the Java program is compiled, a bytecode file will be generated, which is a .class file
8. The following statements are correct ()
A. The constructor in class cannot be omitted
B. The constructor must have the same name as the class, but the method cannot have the same name as the class
C. The constructor is executed when an object is new
D. A class can only define one constructor
Answer: C
9. Execute the following program code ()
a=0;c=0; do{ ——c; a=a-1; }while(a>0);
Answer: C
do{...}while(...); statement is executed at least once10. Which of the following statements is correct ()
A. The abstract modifier can modify fields, methods and classesB. The body part of the abstract method must be surrounded by a pair of braces {}C. When declaring an abstract method, braces are optional. D. When declaring an abstract method, braces are not allowed.Answer: D
Analysis: abstract cannot modify fields. Since it is an abstract method, of course it is an unimplemented method and has no body part at all.11. The following statement is correct ()
A. Formal parameters can be regarded as local variablesB. Formal parameters can be modified by field modifiers
C. Formal parameters are the parameters that are actually passed when the method is called
D. Formal parameters cannot be objects
Answer A:
Analysis:
A: Formal parameters can be regarded as local variables. Formal parameters and local variables cannot leave methods. They will only work within the method, and can only be used within the method, and will not be visible outside the method.
B: Only the final modifier can be used for formal parameters. Any other modifier will cause a compiler error. However, there are certain restrictions on using this modifier, that is, no modifications can be made to the parameters in the method. However, in general, the formal parameters of a method do not need to be modified with final. Only in special cases, that is: methods inside classes. If an inner class within a method uses parameters or local variables of this method, the parameters or local variables should be final.
C: The value of the formal parameter is changed according to the caller when calling, and the actual parameter uses its own value to change the value of the formal parameter (pointers and references are all in this column), that is to say, what is actually passed is Arguments.
D: The parameter list of the method specifies what kind of information is to be passed to the method, all in the form of objects. Therefore, the type and name of each passed object must be specified in the parameter list. Like any situation where objects are passed in JAVA, what is passed here is actually a reference, and the type of the reference must be correct.
The above is the detailed content of A complete collection of Java written test questions with answers (classic 11 questions). For more information, please follow other related articles on the PHP Chinese website!