This question is from a practice
test on the CD accompanying SCWCD Exam Study Kit:
-----------
Question ID :997972318804
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 AudioBook extends Book
{
private String isbn;
public AudioBook(){ isbn = "UNDEFINED_AUDIOBOOK"; }
public String getIsbn(){ return isbn; }
public void setIsbn(String value){ this.isbn = value; }
}
Code for browse.jsp:
<
jsp:useBean class="com.bookstore.AudioBook" type="com.bookstore.Book" id="bookorcd" />
<jsp:getProperty name="bookorcd" property="isbn" />
What is printed in the generated response of browse.jsp?
-----------
Answers:
A. UNDEFINED_BOOK
B. UNDEFINED_AUDIOBOOK
C. It will not compile
D. It will compile but will give an exception at request time
-----------
The correct answer is supposedly B. But, the AudioBook class is declared in a file called MusicCD.java. So the compiler should complain that the class should be declared in AudioBook.java and, hence, the correct answer should be C.
The answer B would be correct if the class was declared in the file called AudioBook.java.
Am I right or am I missing something? Any thoughts?
Thanks!
Milena