Java popular written examination questions arranged

  • 2020-11-26 18:49:08
  • OfStack

This site has compiled a list of some of the most popular written tests in 2017 for those interviewing Java programmers. If you're a reader preparing for an interview with Java programmer, take a look.

1. The following statement is true of ()

A.1 file can have two public decorated classes

B. Constructor can be overridden (override)

C. Subclasses cannot access properties that are not modified by public and protected in the parent class

D. final - decorated classes can be inherited

Answer: C

There can be no more than 1 public class in 1 Java source file. When there is 1 public class, the source file name must be sent to 1, otherwise it cannot be compiled. If there is no public class in the source file, there is no requirement of 1 genicity in the file name and class. As for main(), you don't have to put it in the public class to run the program.

Override is when a child inherits a parent class and modifies the parent class's methods. Method name, argument, and return value must be 1. You cannot override the method marked final. You cannot override a method if you cannot inherit from it.

Extension: The difference between overriding override and overloading overload

java's method overloading

It is possible to create multiple methods in a class that have the same name but different parameters and different definitions. Methods are called to determine which method to use by the different number and type of arguments passed to them, and return value types can be the same or different, which is also object-oriented polymorphism.

java's method is overridden

The polymorphism between the parent class and the child class redefines the function of the parent class. If a method is defined in a subclass that has the same name and parameters as its parent class, we say that the method is overridden (Overriding). In Java, subclasses can inherit methods from the parent class without having to rewrite the same methods. But sometimes a subclass doesn't want to inherit the parent's methods exactly, but wants to make a definite change, which requires method overrides. Method overrides are also called method overrides.

If a method in a subclass has the same method name, return type, and parameter table as a method 1 in a parent class, the new method overrides the old one. For methods that are native to the parent class, use the super keyword, which refers to the parent class of the current class.

The access modifier permission of the subclass function cannot be less than that of the parent class;

Overriding methods can only exist in a relationship with inheritance, and overriding methods can only override methods that are not private to the parent class.

2, for (int x = 0, y = 0; (y! = 0) & & (x < 4); The x++) loop executes ()

A. Unlimited times

B. Performed 4 times

C. Executed three times

D. Not once

Answer: D

The initial value of y is 0. The value of y does not change during the whole cycle of for. =0) is not true, so it is not executed once.

3. Regarding the JAVA heap, the following statement is wrong: ()

A. All instances and arrays of classes are allocated memory on the heap

B. The heap memory occupied by the object is reclaimed by the automatic memory management system

C. Heap memory consists of living and dead objects, free shard areas

D. arrays are allocated in the stack

Answer: D

First, the array is allocated in the heap, so D is incorrect.

Structure of the Java heap: The heap of JVM is the runtime data area, and all instances and arrays of classes are allocated memory on the heap. It was created when JVM started. The heap memory occupied by the object is reclaimed by the automatic memory management system, or garbage collector. Heap memory is made up of living and dead objects. Live objects are accessible to the application and are not garbage collected. Dead objects are those that are inaccessible to the application and have not yet been collected by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.

4. When using the super and this keywords, the following description is correct: ()

A. Use super () in the subclass constructor to show the constructor that calls the parent class;

super () must be written in line 1 of the subclass constructor or the compilation will not pass

B.super () and this () do not have to be placed in line 1 of the constructor

C.this () and super () can appear in 1 constructor at the same time

D. this () and super () can be used in the static environment, including the static method and static statement block

Answer: A

The Java keyword this can only be used in method bodies. When an object is created, the Java virtual machine (JVM) assigns the object a pointer that refers to itself, which is called this. Therefore, this can only be used in non-static methods in a class, and this must not occur in static methods and static code blocks.

super is similar to this in that it is used to render a masked member variable or member method visible, or to refer to a masked member variable or member method.

super, however, is used in subclasses to access the masked members of the immediate superclass, note the immediate superclass (the nearest superclass above the class)

5. Which of the following statements is correct ()

A. Java program produces machine code after compilation

B. Java program produces byte code after compilation

C. Java produces DLL when compiled

D. None of this is true

Answer: B

Java bytecode is an intermediate file produced by compilation of Java source files

java virtual machine is an imaginary computer that can run java bytecode and java is also cross-platform relative to other programming languages.

First, the compilation process of c language is introduced: the c file is compiled by the C compiler to generate the windows executable file exe file and then executed in windows.

The java file is compiled by the java compiler, and the java bytecode file is the class file is executed in the java virtual machine. The machine code is performed by CPU; Java is compiled as bytecode.

Computers can only run machine code. Java turns bytecode into machine code when it runs. C/C++ is compiled directly into machine code at compile time

Which of the following statements is true ()

The ES227en. abstract modifier modifies fields, methods, and classes

B. The body part of an abstract method must be wrapped with 1 pair of curly braces {}

C. Declare abstract methods. Curly braces are optional

D. Declare that abstract methods cannot write curly braces

Answer: D

abstract modifiers are used to modify class and member methods

Classes decorated with abstract represent abstract classes that are located at the abstraction layer of the inheritance tree and cannot be instantiated.

Abstract methods are represented by abstract modified methods, which have no method body. Abstract methods describe what a system does, but do not provide a concrete implementation.

Abstract is an important keyword in Java that can be used to modify a class or a method.

When you decorate a method, it means that the method has only a signature (signature) and no concrete implementation, leaving the concrete implementation to the subclass that inherits the class, so you can't have curly braces.

7. The following statements are correct:

A. constructor in class cannot be omitted

B. constructor must have the same name as class, but the method cannot have the same name as class

C. constructor executes when an object is new

D. One class can only define one constructor

Answer: C

The only difference between a normal class method and a constructor is that the constructor does not return a value.

8, whether GC thread is daemon thread ()

The answer is:

Threads are divided into daemon threads and non-daemon threads (that is, user threads).

As long as any one non-daemon thread exists in the current instance of JVM and does not end, the daemon thread is fully working. The daemon thread ends with JVM1 only when the last non-daemon thread ends.

The most typical application of daemon threads is GC (garbage collector)

9. Regarding sleep() and wait(), the following item describing the error is ()

A. sleep is the method of the thread class (Thread), and wait is the method of the Object class.

B. sleep does not release the object lock, and wait abandons the object lock;

C. sleep suspends the thread, but the monitoring state is still maintained, and will automatically resume after the end;

D. wait enters the waiting lock pool after issuing the notify method for this object, and the object lock is only obtained after issuing the notify method for this object.

Answer: D

sleep is a method of the thread class (Thread) that causes this thread to suspend execution for a specified period of time, giving it a chance to execute on other threads, but the monitoring state remains and will be restored automatically after that time. Calling sleep does not release the object lock.

wait is a method of Object class. Calling the wait method on this object causes the thread to abandon the object lock and enter the waiting lock pool waiting for this object. Only after issuing the notify method (or notifyAll) on this object, the thread enters the object lock pool ready to acquire the object lock and enter the running state.

10, method resume() is responsible for restoring which threads of execution ()

A, the thread stopped by calling the stop() method.

B, the thread stopped by calling the sleep() method.

C, the thread stopped by calling the wait() method.

D, the thread stopped by calling the suspend() method.

Answer: D

suspend can suspend a thread, that is to suspend the thread, it takes up resources, but does not run, using resume is to resume the suspended thread, let the thread continue to execute.


Related articles: