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.acme.MusicCD" id="bookorcd" />
<jsp:getProperty name="bookorcd" property="isbn" />
What is printed in the generated response of browse.jsp?
Options
Select 1 correct option.
1. UNDEFINED_BOOK
2. UNDEFINED_CD
3. It will not compile
4. It will compile but will give an exception at request time.
correct answer is 3
my answer is 4.
My explanation.Since MusicCD doesn't extends Book, it will throw ClassCastException.ClassCastException is a runtime exception not a compile time exception.but why the answer is 3?