


A complete collection of Java written test questions with answers (classic 11 questions)
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo
