Java Written test Bank (05 issue)
Whether the 1,volatile keyword guarantees thread safety. ()
Answer: No
The volatile keyword is used in multithreaded synchronization to ensure read visibility, and the JVM simply guarantees that the value from main memory load to thread working memory is the most recent read value, not the cache. However, thread safety is not guaranteed by multiple threads writing to volatile.
If thread 1, thread 2, in the read,load operation, discovers that the value of count in main memory is 5, then the newest value is loaded, and after the thread 1 is modified for count, it is write into main memory, and the count variable in main memory becomes 6 Thread 2 because the read,load operation has already been performed, the variable value of the main memory count is also updated after the operation, causing two threads to volatile the keyword in a timely manner, or there will be concurrent conditions.
2, which of the following stream classes belong to the character-oriented input stream ()
A, BufferedWriter
B, FileInputStream
C, ObjectInputStream
D, InputStreamReader
Answer: D
Java IO operations have both byte-and character-oriented (Character) methods.
Byte-oriented operations operate on binary data in 8-bit units and do not convert data, which are subclasses of InputStream and OutputStream.
Character-oriented operations manipulate data in characters, convert binary data to characters when they are read, and convert characters to binary data when they are written, which are subclasses of reader and writer.
3,java can not create an object through a constructor ()
A, can B, can't
Answer: A
Several ways to create objects in Java:
(1) Create objects with the new statement, which is the most common method of creating objects.
(2) Using reflection means, invoke Java.lang.Class or Java.lang.reflect.Constructor class newinstance () instance method.
(3) Invoke the Clone () method of the object.
(4) The ReadObject () method of Java.io.ObjectInputStream object is invoked by means of deserialization.
(1) and (2) will explicitly call the constructor explicitly, (3) to photocopy the existing object on memory, so the constructor is not invoked, (4) is the object that restores the class from the file, and the constructor is not invoked.
4, which of the following statements is correct ()
A. Subclasses inherit the constructor method of the parent class.
Subclasses of the B.abstract class must be non-abstract classes.
C. Subclass-Inherited methods can only manipulate member variables that are inherited and hidden by subclasses.
D. Subclass overrides or new methods can also directly manipulate the member variables hidden by the quilt class.
Answer: C
A subclass is a constructor that does not inherit from the parent class, but rather must call its parent class's construction method.
The subclass of an abstract class can be an abstract class, and if it is a non-abstract class, you must override all the abstract methods in the parent class.
D Neutron class New method is not directly manipulate the quilt class hidden member variables.
5, which of the following statements is correct ()
A.final classes can have subclasses.
There can only be an abstract method in the B.abstract class.
The C.abstract class can have a non-abstract method, but the method cannot be decorated with final.
D. It is not possible to modify the same method with final and abstract at the same time.
E. Allow the use of static to modify the abstract method.
Answer: D
The final decorated class is not allowed to be inherited, a error
There can also be normal member methods in the abstract class, b error
Non-abstract methods in an abstract class can be modified with final, and the abstract method cannot be modified by final, c error
D Ditto, correct
Using static to modify the abstract method is not allowed, e error.
6, when retrieving a compressed file, first create a compressed file input stream object, the object ()
A, the selected compressed file as a parameter
B, the FileInputStream object as a parameter
C, take the InputStreamReader object as the parameter
D, the BufferedReader object as a parameter
Answer: B
The ability to manipulate compressed files is provided in the java.io package. It is realized by compressing file input stream and compressing file output stream, which inherits from Inflaterinputstream and Deflateroutputstream respectively.
When you create a compressed file input stream, its initialization parameter is an instance of the FileInputStream class.
7, known an ordered linear table () (13,18,24,35,47,50,62,83,90,115,134), when the binary lookup of the value of 90 elements, the number of successful comparisons to find ()
a,1 b,2 c,3 d,9
Answer: B
It takes two times to find according to the binary: first, compare 90 with the element 50 in the middle of the table, because 90 is greater than 50, so look in the second half of the linear table, and the next element is the middle element of the latter part, that is 90, and then the two are equal, that is
The concurrency mechanism of the 8,java program is ()
A. Multithreading
B. Multi-Interface
C. Multi-platform
D. Polymorphism
Answer: A
Java is the implementation of the concurrency mechanism through multithreading. Multithreading means that a program contains multiple execution flows, and the meaning of multithreaded program design is that it can be divided into several parallel subtasks.
9, the following options, which are not coupled between modules are ()
A. Data coupling
B. Tag coupling
C. Heterogeneous coupling
D. Public-coupled
Answer: C
The degree of coupling between modules reflects the independence of modules, and also reflects the complexity of the system after decomposition. According to the degree of coupling from weak to strong, it can be divided into 7 levels.
They are indirect coupling, data coupling, tag coupling, control coupling, external coupling, public coupling and content coupling. There is no heterogeneous coupling in this way.
10, the following statement about the internal class is not correct ()
A, the class name of the inner class can only be used anonymously in the class or program segment where it is defined or inside the expression
B, the inner class can use static member variables and instance member variables of the class in which it resides
C, the inner class cannot be defined as an abstract class with the abstract modifier
D, an inner class can be a member of another class and can access the members of its class
Answer: C
An inner class can be defined not only as an abstract class, but also as a private or protected definition, so option C is a bad idea.