aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt on mock exam question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt on mock exam question?" Watch "doubt on mock exam question?" New topic
Author

doubt on mock exam question?

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
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?
peter greaves
Ranch Hand

Joined: Sep 27, 2002
Posts: 51
i would guess a compile time error is because the package name of the type can't be resolved? it is bookstore, not acme?


SJCP 1.2
Neeraj Singhal
Ranch Hand

Joined: Aug 13, 2000
Posts: 49
According to JSP Specification:
At least one of type and class must be present, and it is not valid to provide both class and beanName. If type and class are present, class must be assignable to type (in the Java platform sense). For it not to be assignable is a translation-time error.
Means...answer 3 is correct, since it is translation time error.
Sathya Sankar
Ranch Hand

Joined: Sep 16, 2000
Posts: 67
Raymond,
Got to see this thread pretty late. Peter said it right:
i would guess a compile time error is because the package name of the type can't be resolved? it is bookstore, not acme?

The first step in "executing" a jsp is to compile it into it's equivalent servlet. The container does it by first converting the jsp into an equivalent .java file and then attempting to compile it into it's .class representation. This compilation fails because com.acme.MusicCD is not in it's classpath.
So the right answer is option 3.
Ciao,
GSS


SCJP, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on mock exam question?
 
Similar Threads
Cloning Question
beginner one-to-one problem
relation is required B/W class and type before <useBean>
JWebPlus exam question
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property