• 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

relation is required B/W class and type before <useBean>

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following java code:



Just to share this knowledge .....


Detailed Explanation

Concept: Whenever you see class and type attribute both in the use bean tag, visualize the tag like this:
typevalue obj = (typevalue) new classValue;
And see, if it is valid at compiletime and runtime.


Here, applying the same logic we get:
MusicCD obj = (MusicCD) new Book();
It is clear that you cannot cast a Book object to MusicCD object because MusicCD does not extend from Book. So this is a compile time error.

so relation is required between class amd type attribute before the use of <useBean> tag in JSP.


 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3. It will not compile is the correct answer
 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for you aclaration.

But I dont think that the translation will be:

MusicCD obj = (MusicCD) new Book();

I think, that this will be:

MusicCD obj = new Book(); //without the casting.

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope Milton , this is not the option. Polymorphisam will be applied here.
MusicCD obj = (MusicCD) new Book();

This way you can call the MusicCD methods as well.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This way you can call the MusicCD methods as well.

-->How is it possible?The code wont get compiled right?


Chithra Salam
SCJP -85%,SCWCD-in progress.
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code, will compile

the problem is when the JSP is translating to a Servlet <- this wont compile, for the problems of pholymorph
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is very nicely explained here: http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic