Java basis of written exercises (three)

Here Insert Picture Description

1. The following InputStream class in which the method can be used to shut down stream?

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

The answer:
B

Analytical:
InputStream stream close method Close to
Skip () is used to skip some byte
mark () is used to mark stream
reset () Reset flow

2. The following statement is correct ()

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

The answer:
D

Analysis:
Option D, + =, - =, * =, / = most common.
ABC are compilation errors.

3. The following description of the inheritance is correct?

A. In Java allows only single inheritance
B. can only implement an interface in Java a class
C. A class can not inherit the same time and in Java a class implements an interface
D.Java the inheritance of a single code is not reliable

The answer:
A

Analysis:
slightly

4. Which of the following statements are true?

A. Examples of the method can be called the direct superclass method of Example
B. Example callable methods based direct superclass
C. instance of class class method of the present method may be called directly
D. Examples of other methods can be called directly class instance method

The answer:
C

Analytical:
. Examples of A can invoke superclass method public instance methods
. Examples of method B can call public class superclass
d instance of class class method other methods can be called by the class name.

5.A to subclass B, B to subclass C, and the following statement in the source code java:

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

Which of the following statements are true?

A. line 1, line 2 and line 3 declaration are correct
B. 1,2,3 line can compile, but the second and third row runtime error
C. The first and second rows can compile, but the third line compiler error
D. compiled through only the first line

The answer:
A

Analysis:
word upward transition is unconditional

6.java, the static variables static address is the same in different instances in different threads? They are stored in what area? ()

A. address, as in the stack area.
B. is not the same address, in the stack area.
Like C. addresses in the global zone.
D. address is not the same as in the global zone.

The answer:
C

Parse:
static variables are stored in the method area, threads share, global area is part of the method area, in fact, with the exclusion you may also know that static variables can not be located in the stack area

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);
  }
}

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

The answer:
D

Analytical:
. 1, Inti = 100/0; exception occurs, an exception is thrown, System.out.print (i) is not performed,
2, the catch catches the exception and continue execution of System.out.print (. 1);
. 3, when performing thrownewRuntimeException (); will throw an exception, then, in addition to finally execute code in other parts of the code will not be executed

8. The following code will print out?

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);
}

A. compilation errors
B.true to true
C.true false
D.false false

The answer:
B

Analysis:
collection (ArrayList, LinkedList) collection type of data object type can only be charged, the charged title 0, a basic type, but after JDK5 provides automatic and automatic packing unpacking, so automatic type int packing becomes the Integer type. Compiled by the normal.
The reference to the assignment list1 list2, then list1 and list2 will point to the same heap memory space. instanceof in Java keyword for determining whether an instance of an object belongs to a particular class, and return a return value of the boolean type. Obviously, list1.get (0) and list2.get (0) are all examples of Integer

9. In operation, automatically introduced by the java interpreter, rather than introduced into the bag is import statement ().

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

The answer:
A

Analytical:
ava.lang packet is a java language pack is imported automatically.
java package is java.util kit, need to manually import.
java.sql package, JDBC interface class, need to manually import.
the java.io; various input streams, need to manually import.

10. The following three statements

System.out.println(“is ”+ 100 + 5);
System.out.println(100 + 5 +“ is”);
System.out.println(“is ”+ (100 + 5));

The output results were? ()

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

The answer:
D

Analytical:
1. "is" the content will be described later cast string, so the final result is spliced together
2.100 + 5 to obtain 105, and is then spliced
3. first count parenthesis

11.Given:

public class IfTest{
    public static void main(string[]args){
        int x=3;
        int y=1;
        if(x=y)
            System.out.println(“Not equal”);
        else
            System.out.println(“Equal”);
     }
}

What is the result?

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

The answer:
C

Resolution:
This title examines the two knowledge points.
1, Java, the assignment is a return value, assigned what value, what value to return. For example, this problem, x = y, return the value of y, so the value of 1 in parentheses.
2, C difference with the Java, C after the assignment will be compared with 0, if greater than 0, it is considered to be true; but Java does not compare to 0, but directly to the result of the assignment into the brackets.

12. In a server-based distributed gaming systems, among different servers, what kind of communication is not feasible ()?

A. conduit
B. message queues
C. Cache Database
D. socket

The answer:
A

Analysis:
pipe (pipe): pipe is a half-duplex communication mode, data flows only one way, but only with the use of genetic relationship between processes. Kinship process usually refers to the process of parent-child relationship.

13. The following program run results

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!");
    }
}

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

The answer:
A

Analysis:
topic that throws an exception, but did not say specifically what is abnormal, then they would divide the situation:
1. If you throw a FileNotFoundException (or subclass), then the end result is print FileNotFoundException
2. If you throw a IOException, or subclass of IOException (FileNotFoundException does not contain its subclasses), then the end result is print IOException
3. If you throw an Exception (not included IOException and its subclasses), then the end result is print Exception.
above, so three things are possible. However, no matter what kind of situation will only output one of them.
The answer from the point of view, where the output B, C, D are not present. So choose A

14. What is the output of the following code is?

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);
    }
}

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

The answer:
D

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

15. The following description of the servlet and cgi, the statement is wrong?

A.servlet in the server process, which runs its service method by multiple threads
B.CGI has produced a new process for each request, after the service is completed destruction
C.servlet on ease of use is stronger than cgi, which provides a large number of utility routines, for example, automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, to track the session status
D.cgi above servlet on portability, nearly all major servers directly or by plug-in support cgi

The answer:
D

Analysis:
select D, servlet in the server process, which runs its service method by multiple threads, an instance can service multiple requests, and the examples are generally not destroyed, CGI has produced a new process for each request, after the service is completed destroyed, so efficiency is lower than the servlet.

16. The following description about the construction method, the error is ()

A.java language provisions constructor name and the class name must be the same
B.java language provisions of the constructor does not return a value, but different void statement
C.java language provisions can not be overloaded constructor
D.java language can only be prescribed by new construction method automatic call

The answer:
CD

Analysis:
About answer d, also can be called by 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 accessed directly by the class name and doesn’t need any object

The answer:
ABC

Resolution:

A: static method is a method not part of the class object (instance) belong. (√)
B: static methods can only access static data. You can not access non-static data (instance variables). (√)
C: Static methods can only call other static methods can not call non-static method from. (√)
D: Static methods can not be directly accessed by the class name, do not need any object. (×) static method can directly access the class name.

18. Which of the following would call the copy constructor ()

A. A derived class of the object when the object is to initialize the base class
B. A class assignment of an object to another object class when
the object is a class parameter C. function calls and function parameter arguments when combined
D. the return value is a function of the object class, when execution returns to the calling function

The answer:
ACD

Resolution:

Copy the three cases constructor is called

1. defines an object to another object of this class as the initial value, the occurrence of copy configuration;

2. If the object shape parameter is a function of the class, the function is called using arguments object initialization parameter object replication occurs configuration;

3. If the return value is a function of the object class, a function performed upon completion return to the calling function, object initialization uses a return statement in a temporary object is unknown, is passed to the calling function, the copy constructor occurs at this time.

19.Java initialized object has ()

A. initialization block
B. constructor
specifies the initialization values define the variable C.
D. None of the other

The answer:
ABC

Resolution:

Initialized object:
initializing 1.New;
2. static factory the newInstance;
3. reflecting the Class.forName ();
4.clone embodiment;
5. deserialization;

20. As of JDK1.8 version, java concurrency framework, including support lock?

A. write lock
B. spin locks
CX lock
D. optimistic locking
E. exclusive lock

The answer:
ABD

Resolution:

1, the spin lock, spin, jvm default is 10 times it has jvm own control. to fight for lock
2, blocking locks blocked thread does not lock contention.
3, reentrant lock several times to change the locks to enter the domain
4, read-write locks
5, mutex lock itself is mutually exclusive
6, pessimistic locking do not believe that it would be a safe, we must all be locked
7, optimistic locking I believe, here it is safe.
8, fair locks have priority lock
9, unfair priority lock lock no
10, no competition is not biased locking lock, competitive hangs into lightweight lock
11, the object lock to lock an object
12, thread lock
13 , locks into a lock coarsening plurality own processing
14, CAS achieve lightweight lock
15, the lock is biased locking eliminate eliminate a lock
16, the lock inflation jvm achieved, lock coarsening
17, blocking locks implemented using semaphores one strategy
18, exclusive locks: X lock, if the transaction data object a plus T X lock only allows read and modify T a, no other transaction can no longer applied to any type of lock a until release the lock on T a. This ensures that other transactions can not be read and modified before T release the lock on A A.

Note: The above document questions are from the network, given by the author finishing

recommend

Manufacturers written content collection (with detailed analytical) continuously updated in ....

ProcessOn aggregation platform is an online mapping tool -

The end of the sentence

Welcome attention to personal micro-channel public number: Coder programming
welcome attention Coder programming public numbers, the main share data structures and algorithms, Java-related knowledge, the framework of knowledge and principle, Spring family bucket, micro-services project combat, DevOps practices of the road, one day Internet giant pen articles or interview questions and PMP project management knowledge. More exciting content is on the way -
built a qq group: 315 211 365, we welcome into the group exchange study together. Thank you! Can also be introduced to the side of a friend in need.

Articles included to
Github: https://github.com/CoderMerlin/coder-programming
Gitee: https://gitee.com/573059382/coder-programming
welcome attention and star ~
Micro-channel public number

Guess you like

Origin www.cnblogs.com/coder-programming/p/11683556.html