当前位置: > 这道题目的答案是不是有问题啊...
题目
这道题目的答案是不是有问题啊
具体的题目是这样的:
Consider the following java code:
//in file Book.java
package com.bookstore;
public class Book
{
private String isbn;
public Book(){ isbn = "UNDEFINED_BOOK"; }
public String getIsbn(){ return isbn; }
public void setIsbn(String value){ this.isbn = value; }
}
//in file MusicCD.java
package com.bookstore;
public class MusicCD
{
private String isbn;
public MusicCD(){ isbn = "UNDEFINED_CD"; }
public String getIsbn(){ return isbn; }
public void setIsbn(String value){ this.isbn = value; }
}
Code for browse.jsp:


What is printed in the generated response of browse.jsp?
Select 1 correct option.
a.UNDEFINED_BOOK
b.UNDEFINED_CD
c.It will not compile
d.It will compile but will give an exception at request time.
它的答案说是选C 说不会通过编译的 可是我个人感觉应该是选D的 会通过编译只是会抛出ClassCastException的 大家都怎么认为

提问时间:2021-04-02

答案
下面是在tomcat下运行后的错误显示:
org.apache.jasper.JasperException:Unable to compile class for JSP:
JSP FileName:/pp.jsp
Java FileName:/D:/Tomcat5.5/work/Catalina/localhost/test//org/apache/jsppp_jsp.java
An error occurred at line:14 in the jsp file:/pp.jsp
Type mismatch:cannot convert from Book to MusicCD
11:
12:
13:
14:
15:
16:asdfasdfasdfasdfasdfsadf
17:
所以确实是无法编译的,至于原因,是因为这两个类没有任何联系,想通过Book bookorcd= new MusicCD()
赋值,很明显,这是错误的
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.