1. Which method of the following InputStream class can be used to close a stream?

A.skip () B.close () C.mark () D.reset ()

Answer: B

Skip () is used to skip a few bytes. Mark () is used to mark the stream. Reset () is used to reset the stream

2. Which of the following statements is correct?

A.x+1=5 B.i++=1 C.a++b=1 D.x+=1

Answer: D

A += B -= C *= D /= ABC all compile error.

3. Which of the following is true about inheritance?

A. Only single inheritance is allowed in Java B. Only one interface can be implemented by A class in Java C. In Java, a class cannot inherit from both a class and implement an interface.Java’s single inheritance makes code unreliable

Answer: A,

Analytic: slightly

Which of the following statements is true?

A. Instance methods can directly call instance methods of the superclass. B. Instance methods can directly call class methods of the superclass. Instance methods can directly call the class methods of their own class D. Instance methods can directly call instance methods of other classes

Answer: C

A. Instance methods can call superclass public instance methods b. instance methods can directly call superclass public class methods D. Instance methods can call class methods of other classes by class name

5.A subclass B, B subclass C, and Java source code has the following declaration:

1.A a0=new A();
2.A a1=new B();
3.A a2=new C();
Copy the code

Which of the following statements is true?

A. Lines 1,2, and 3 are declared to be correct B. Lines 1,2, and 3 will compile, but lines 2,3 will run in error C. Lines 1,2 will compile, but line 3 will compile in error D. Only line 1 will compile

Answer: A,

In a word, upward transformation is unconditional

In Java, does the static variable static have the same address in different instances of different threads? What area are they stored in? (a)

A. Address the same, in the stack area. B. The address is in the stack area. C. The address is the same in the global area. D. The address is in the global area.

Answer: C

Static variables are stored in the stack, shared by threads. The global stack is part of the stack

7. What is the output of the following code?

public class ZeroTest { public static void main(String[] args) { try{ int i = 100 / 0; System.out.print(i); }catch(Exception e){ System.out.print(1); throw new RuntimeException(); }finally{ System.out.print(2); } System.out.print(3); }}Copy the code

A.3 B.123 C.1 D.12

Answer: D

1, inti = 100/0; Print (I); print(I); print(I); print(I); print(I); 3. Execute thrownewRuntimeException(); An exception is thrown, and no code will execute except the code in finally

8. Will the following code be printed?

public static void main(String args[]) {
      List  Listlist1 = new ArrayList();
      Listlist1.add(0);
      List Listlist2 = Listlist1;
	  System.out.println(Listlist1.get(0) instanceof Integer);
	  System.out.println(Listlist2.get(0) instanceof Integer);
}

Copy the code

A. Compilation error B. truetrue C. truefalse d. false false

Answer: B

ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList = ArrayList Compilation passes normally. Assign a reference to list1 to list2, then list1 and List2 will both point to the same heap memory space. Instanceof is a Java keyword that determines whether an object belongs to an instanceof a particular class and returns a Boolean return value. Obviously, list1.get(0) and list2.get(0) are both instances of Integer

9. The package that is automatically imported at runtime by the Java interpreter without an import statement is ().

A.java.lang B.java.system C.java.io D.java.util

Answer: A,

The ava.lang package is a Java language package that is automatically imported. The java.util package is a Java toolkit that needs to be imported manually. The java. SQL package, JDBC interface class, needs to be imported manually. java.io; Various input input streams need to be imported manually.

10. The following three statements

System.out.println(" is "+ 100 + 5); System.out.println(100 + 5 + "is"); System.out.println(" is "+ (100 + 5));Copy the code

Are the output results of? (a)

A.is 1005, 1005 is, is 1005 B.is 105, 105 is, is 105 C.is 1005, 1005 is, is 105 D.is 1005, 105 is, is 105

Answer: D

1.”is” = 2.100+5 = 105, then = 3. Let’s do the parentheses first

11.Given:

public class IfTest{
    public static void main(string[]args){
        int x=3;
        int y=1;
        ifSystem. (x = y) out. Println (" Not equal ");elseSystem. The out. Println (" Equal "); }}Copy the code

What is the result?

A. Output is “Equal” B. output in “Not Equal” C. error at line 5 causes compilation to fall.d. he program executes but does not print a message.

Answer: C

A. is b. is C. is D. is 1. In Java, assignment returns a value. So this one, x equals y, returns the value of y, so the value in parentheses is 1. 2, The difference between Java and C, C will be compared with 0, if greater than 0, it is considered true; Java does not compare to 0, but puts the result of the assignment in parentheses.

12. In a distributed game server system, which communication mode between different servers is not feasible ()?

A. pipeline B. message queue C. cache database D. socket

Answer: A,

Pipe: A half-duplex communication mode in which data flows only in one direction and is used only between related processes. Process kinship usually refers to the parent-child process relationship.

13. Results of the following procedures

public void getCustomerInfo() {
	try {
		// do something that may cause an Exception
	} catch (java.io.FileNotFoundException ex) {
		System.out.print("FileNotFoundException!");
	} catch (java.io.IOException ex) {
		System.out.print("IOException!");
	} catch (java.lang.Exception ex) {
		System.out.print("Exception!"); }}Copy the code

A.IOException! B.IOException! Exception! C.FileNotFoundException! IOException! D.FileNotFoundException! IOException! Exception!

Answer: A,

C) An exception is raised. D) an exception is raised. If a FileNotFoundException(or a subclass thereof) is thrown, the end result prints FileNotFoundException 2. If an IOException, or a subclass of IOException (excluding FileNotFoundException and its subclasses) is thrown, the end result prints IOException 3. If an Exception(excluding IOException and its subclasses) is thrown, the end result prints Exception. Above, so all three are possible. However, in either case, only one or the other will be printed. B,C, D So choosing A

14. What is the output of the following code?

public class Test {
    public int aMethod(){
        static int i = 0;
        i++;
        return i;
    }
public static void main(String args[]){
    Test test= new Test(); test.aMethod(); int j = test.aMethod(); System.out.println(j); }}Copy the code

A.0 B.1 C.2 D. Compilation failed

Answer: D

Static variables can only be defined in the body of a class, not in a method

15. Which of the following statements about servlets and CGI is wrong?

C. Servlet is better than CGI in ease of use. It provides a large number of utility routines. For example, the ABILITY to automatically parse and decode HTML form data, read and set HTTP headers, handle cookies, and track session state is more portable than servlets, and almost all major servers support CGI directly or through plug-ins

Answer: D

A servlet can run its service method in a multithreaded manner. An instance can serve multiple requests, and instances are generally not destroyed. CGI creates a new process for each request and destroys the service after completion.

16. What is wrong with the following statement about the construction method?

A. Java specifies that the constructor name must be the same as the class name. B. Java specifies that the constructor does not return a value, but the void declaration is different. C. Java specifies that the constructor cannot be overloaded

Answer: the CD

A. this B. this C. this D. this

17.What is Static Method in Java ()

A.It is a method which belongs to the class and not to the object(instance) B.A static method can access only static data. It can not access non-static data (instance variables) C.A static method can call only other static methods and Can not call a non-static method from it.d.a static method can not be directly by the class name and doesn’t need any object

Answer: ABC

Resolution:

A: A static method is A method that belongs to A class rather than an object (instance). (√) B: Static methods can access only static data. Non-static data (instance variables) cannot be accessed. (√) C: static methods can only call other static methods. Non-static methods cannot be called from static methods. (√) D: Static methods cannot be accessed directly by class names and do not require any objects. Static methods can be accessed directly with the class name.

18. Which of the following situations will call the copy constructor ()?

A. Initialize an object of A derived class. B. Assign an object of the class to another object of the class. D. The return value of the function is the object of the class, and the function is executed to return the call

A b C D

Resolution:

Three cases in which the copy constructor is called

1. When an object is defined, another object of this class is taken as the initial value, and replication construction occurs.

2. If the parameter of a function is an object of a class, the parameter object is initialized with the argument object when the function is called, and copy construction occurs.

3. If the return value of a function is an object of a class, when the function returns the calling function after execution, a temporary nameless object is initialized using the object in the return statement and passed to the calling function. At this point, copy construction occurs.

19.Java objects can be initialized by ()

A. Initialize block B. Constructor C. Specify an initialization value when defining A variable D

A B C

Resolution:

Object initialization method: 1. 2. Static factory newInstance; 3. Reflection class.forname (); 4. The clone way; 5. Deserialize;

20. As of JDK1.8, the Java concurrency framework supports locks including?

A. read/write lock b. spin lock C.X lock d. optimistic lock e. exclusive lock

A B C D

Resolution:

1, Spin lock, spin, JVM default is 10, has its own control. A blocked thread does not compete for the lock. Read/write lock 5, mutex lock itself is mutually exclusive 6, pessimistic lock do not believe, here will be safe, must lock all 7, optimistic lock believe, here is safe. 8. Fair lock with priority 9. Non-fair lock with no priority 10. Lock elimination Partial locking is a kind of lock elimination. Lock expansion JVM implementation, lock coarser 17. Semaphores using blocking lock implementation strategy X lock. If transaction T holds X lock on data object A, only T is allowed to read and modify A. No other transaction can hold any lock on A until T releases the lock on A. This ensures that no other transaction can read or modify A until T releases the lock on A.

Note: the above questions are from the network, by the author collated

recommended

Java written test content set welcome attention, continue to update….

At the end of the article

Welcome to focus on individual WeChat public number: Coder programming for the latest original technical articles and free learning materials, is more a large number of high-quality goods, the interview data, mind maps PMP exam information waiting for you to come back, you can anytime, anywhere learning technical knowledge!

Github: github.com/CoderMerlin… Gitee: gitee.com/573059382/c… Welcome to follow and star~