刷题 day 05 Java

1 Java中只有整型才能使用的运算符为©

A *
B /
C %
D +

2 下列代码中的错误是(D)

下列代码中的错误是()

(1)   public class Test
(2)   {
(3)       public static void main(String [] args)
(4)       {
(5)           int i;
(6)           i+=1;
(7)       }
(8)     }

A 非法的表达式
B 找不到符号i
C 类不应该为public
D 尚未初始化变量i

3 下列代码运行错误的是(B )

class B extends Object
{
    static
    {
        System.out.println("Load B");
    }
    public B()
    {
        System.out.println("Create B");
    }
}
class A extends B
{
    static
    {
        System.out.println("Load A");
    }
    public A()
    {
        System.out.println("Create A");
    }
}
 
public class Testclass
{
    public static void main(String[] args)
    {
        new A();
    }
}

不太会看

解析:执行顺序:
父类静态代码块-》子类静态代码块-》父类构造代码块-》父类构造函数-》子类构造代码块-》子类构造函数

4 下面不属于HttpServletRequest接口完成功能的是(C)

A 读取cookie
B 读取HTTP头
C 设定响应的content类型(是response可以干的事)
D 读取路径信息
解析:HttpServletRequest类主要处理:

  1. 读取和写入HTTP头标(Request.getHeader(neam))
  2. 取得和设置cookies (Request.getCookies( ))
  3. 取得路径信息 (Request.getContextPath( ))
  4. 标识HTTP会话

5.int i=5;int s=(i++)+(++i)+(i–)+(–i); s= ( ) s的值是(24)

解析:i++是先取值再加,++i是先加后取值。

回头再看一遍 糊

6. 关于Spring的说法错误的是(D)

A spring是一个轻量级JAVA EE的框架集合
B spring是“依赖注入”模式的实现
C 使用Spring可以实现声明事务
D Spring提供了AOP方式的日志系统

7.package Wangyi;

class Base
{
    public void method()
    {
        System.out.println("Base");
    } 
}
class Son extends Base
{
    public void method()
    {
        System.out.println("Son");
    }
     
    public void methodB()
    {
        System.out.println("SonB");
    }
}
public class Test01
{
    public static void main(String[] args)
    {
        Base base = new Son();
        base.method();
        base.methodB();
    }
}

解析:Base base=new Son(); 是多态的表示形式。父类对象调用了子类创建了Son对象。
base调用的method()方法就是调用了子类重写的method()方法。
而此时base还是属于Base对象,base调用methodB()时Base对象里没有这个方法,所以编译不通过。
要想调用的话需要先通过SON son=(SON)base;强制转换,然后用son.methodB()调用就可以了。

同第三题 不太懂

8 根据下面的代码,String s =null;会抛出NullPointerException异常的有(AC)

A if( (s!=null) & (s.length()>0) )
B if( (s!=null) && (s.length()>0) )
C if( (s==null) | (s.length()0) )
D if( (s
null) || (s.length()==0) )
解析:String s=null;没有给s开辟任何空间,当执行length()方法时候,因为没有具体指向的内存空间,所以报出NullPointerException没有指向的错误。A &是与,位运算,两个都得执行,执行到s.length()自然就报错了。B S!=null 结果为false 整体就为false ,&& 后面就不会执行。下面的同理。

9 Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Which of the following statement(s) is(are) correct?

A Models often represent data and the business logics needed to manipulate the data in the application
B A view is a (visual) representation of its model. It renders the model into a form suitable for interaction, typically a user interface element
C A controller is the link between a user and the system. It accepts input from the user and instructs the model and a view to perform actions based on that input
D The common practice of MVC in weapplications is, the model receives GET or POST input from user and decides what to do with it, handing over to controller and which hand control to views(HTML-generating components)
E None of the above
解析:翻译
MVC是一种在web应用中常用的架构,下列说法正确的是()

A. 模型通常代表应用程序中的数据以及用于操纵数据的业务逻辑;

B. 视图是其对应的模型的可视化呈现,视图 将模型渲染成适合于交互的形式(通常为用户界面元素);

C. 控制器是用户与系统之间的纽带,它接受用户输入,并指示模型和视图基于用户输入执行操作(处理数据、展示数据);

D. MVC模式在web应用中的常见实践是:模型接受来自于用户的GET或POST请求数据并决定如何处理,模型将用户数据转交给控制器,控制器将控制权转交给视图(视图由HTML生成);

E. 以上全不是。

猜你喜欢

转载自blog.csdn.net/phoebeziz/article/details/83243645