Five hours of daily java written test-2020-9-14

Five hours of daily java written test-2020-9-14

  1. The programming language JavaScript of the Web client is derived from Java, and its functions are a subset of Java SE.

    Correct answer: B Your answer: B (correct)

    对
    错
    
  2. Which of the following streams can be used for character input:

    Correct answer: C Your answer: C (correct)

    java.io.inputStream
    java.io.outputStream
    java.io.inputStreamReader
    java.io.outputStreamReader
    

    Analysis:

    First, B and D are eliminated, and the subject is required to be input.
    Between A and C, inputStream is a byte stream input stream;
    inputStreamReader is a character stream processing, inputStreamReader processes a character stream into a byte stream, and the
    subject requirement is for processing character input, so choose C.

  3. What is the output of the following code? *

    public class Base
    {
          
          
        private String baseName = "base";
        public Base()
        {
          
          
            callName();
        }
    
        public void callName()
        {
          
          
            System. out. println(baseName);
        }
    
        static class Sub extends Base
        {
          
          
            private String baseName = "sub";
            public void callName()
            {
          
          
                System. out. println (baseName) ;
            }
        }
        public static void main(String[] args)
        {
          
          
            Base b = new Sub();
        }
    }
    

    Correct answer: A Your answer: B (wrong)

    null
    sub
    base
    

    Analysis:

    Answer: A
    new Sub(); In the process of creating a derived class, first create a base class object, and then create a derived class.
    To create a base class is to call the Base() method by default, and call the callName() method in the method. Because this method exists in the derived class, the called callName() method is a method in the derived class, and the derived class has not been constructed yet , So the value of the variable baseName is null

  4. How to get the parameter value set by ServletContext?

    Correct answer: B Your answer: C (wrong)

context.getParameter()
context.getInitParameter()
context.getAttribute()
context.getRequestDispatcher()

Analysis:

getParameter() is to obtain the parameter value passed by POST/GET;
getInitParameter to obtain the initialization parameter of Context set in Tomcat's server.xml.
getAttribute() is to obtain the data value in the object container;
getRequestDispatcher is to request forwarding.

  1. Which of the following statements about the java constructor is correct ()

​ Correct answer: CD Your answer: BCD (wrong)

构造器的返回值为void类型
如果一个源文件中有多个类,那么构造器必须与公共类同名
构造器可以有0个,1个或一个以上的参数
每个类可以有一个以上的构造器

Analysis:

​ The construction method is a special method with the following characteristics.
​ (1) The method name of the construction method must be the same as the class name.
​ (2) The constructor has no return type and cannot be defined as void. The method type is not declared before the method name.
​ (3) The main function of the construction method is to complete the initialization of the object. It can pass the parameters when defining the object to the domain of the object.
​ (4) A class can define multiple construction methods. If no construction method is defined when the class is defined, the compiler system will automatically insert a default constructor without parameters, which does not execute any code.
​ (5) The construction method can be overloaded, with the number, type and order of the parameters.

Specific ABCD analysis:

(1)A构造函数无返回值,错误; 
  
(2)B中多个类时构造函数不一定与公共类同名,因为每个类都可以有构造函数,函数名同所属类,错误; 
  
(3)C构造器可以有任意个参数,对的; 
  
(4)D每个类都默认有一个构造函数,选项中“一个以上”的描述,让人误解至少要两个,所以错误。 
  
所以答案对错不重要,理解就好。 

Guess you like

Origin blog.csdn.net/qq_37924905/article/details/108573925