• Post Reply Bookmark Topic Watch Topic
  • New Topic

JWebPlus exam question  RSS feed

 
Milena Khlabystova
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Milena,
That must be a mistake as the second file will not even compile since there can only be one public class in a source file and that must match the name of the file.
Ignoring that comment, thought the out put will be b due to polymorphism.
- FK
 
Milena Khlabystova
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is precisely what I thought. Thanks for confirming.
Milena
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
I saw a posting on JDiscuss that there had been some errors in JWebPlus and they are offering a new data bank download. I am not sure if you have to buy the full verion for that or if you can use it with the one that comes with the Study Kit.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!