亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Java JavaInterview questions A complete collection of Java written test questions with answers (classic 11 questions)

A complete collection of Java written test questions with answers (classic 11 questions)

Nov 21, 2019 pm 04:07 PM
java

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);
## After #, the value of c is ()

A. 0

B. 1

C. -1

D. Infinite loop

Answer: C

do{...}while(...); statement is executed at least once

10. Which of the following statements is correct ()

A. The abstract modifier can modify fields, methods and classes

B. 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 variables

B. 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
VSCode settings.json location VSCode settings.json location Aug 01, 2025 am 06:12 AM

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

Mastering Dependency Injection in Java with Spring and Guice Mastering Dependency Injection in Java with Spring and Guice Aug 01, 2025 am 05:53 AM

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

Google Chrome cannot open local files Google Chrome cannot open local files Aug 01, 2025 am 05:24 AM

ChromecanopenlocalfileslikeHTMLandPDFsbyusing"Openfile"ordraggingthemintothebrowser;ensuretheaddressstartswithfile:///;2.SecurityrestrictionsblockAJAX,localStorage,andcross-folderaccessonfile://;usealocalserverlikepython-mhttp.server8000tor

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

See all articles