这道题目的答案是不是有问题啊
具体的题目是这样的:Considerthefollowingjavacode://infileBook.javapackagecom.bookstore;publiccl...
具体的题目是这样的:
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:
<jsp:useBean class="com.bookstore.Book" type="com.bookstore.MusicCD" id="bookorcd" />
<jsp:getProperty name="bookorcd" property="isbn" />
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的 大家都怎么认为啊? 高手能否为我讲解一下 谢谢啊!
可是这两个CLASS之间没有任何 关系啊~~~ 展开
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:
<jsp:useBean class="com.bookstore.Book" type="com.bookstore.MusicCD" id="bookorcd" />
<jsp:getProperty name="bookorcd" property="isbn" />
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的 大家都怎么认为啊? 高手能否为我讲解一下 谢谢啊!
可是这两个CLASS之间没有任何 关系啊~~~ 展开
3个回答
展开全部
下面是在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/jsp\pp_jsp.java
An error occurred at line: 14 in the jsp file: /pp.jsp
Type mismatch: cannot convert from Book to MusicCD
11: <jsp:useBean id="one" class="com.bookstore.TestBean" scope="request"/>
12: <jsp:setProperty name="one" property="name" value="阍熶匠ddddddddddd"/>
13: <jsp:getProperty name="one" property="name"/>
14: <jsp:useBean class="com.bookstore.Book" type="com.bookstore.MusicCD" id="bookorcd" />
15: <jsp:getProperty name="bookorcd" property="isbn"/>
16: asdfasdfasdfasdfasdfsadf
17: </body>
所以确实是无法编译的,至于原因,是因为这两个类没有任何联系,想通过Book bookorcd= new MusicCD()
赋值,很明显,这是错误的
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/jsp\pp_jsp.java
An error occurred at line: 14 in the jsp file: /pp.jsp
Type mismatch: cannot convert from Book to MusicCD
11: <jsp:useBean id="one" class="com.bookstore.TestBean" scope="request"/>
12: <jsp:setProperty name="one" property="name" value="阍熶匠ddddddddddd"/>
13: <jsp:getProperty name="one" property="name"/>
14: <jsp:useBean class="com.bookstore.Book" type="com.bookstore.MusicCD" id="bookorcd" />
15: <jsp:getProperty name="bookorcd" property="isbn"/>
16: asdfasdfasdfasdfasdfsadf
17: </body>
所以确实是无法编译的,至于原因,是因为这两个类没有任何联系,想通过Book bookorcd= new MusicCD()
赋值,很明显,这是错误的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询