• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JWebPlus exam question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic