• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism and useBean

 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a abstract super class called Person with no fields and a concrete subclass with name field . I use the following code in jsp:
<jsp:useBean id="emp" type="com.example.Person" class"com.example.Employee"/>
<jsp:setProperty name="emp" property="name" value="bernard" />
<jsp:getProperty name="emp" property="name"/>

The above works well . But in HFS they mention we can get and set properties that exist for the type and normal java polymorphism applies.
But when I try it is different and the generated source code has a call to some introspect... method . Can someone help to clarify this .
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys ,

Anybody has tired this yet ? I guess there is a realistic chance of this kind of questions to appear in the exam .
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Person has no fields, I'm not sure what properties you would be setting or getting in the type. I'd like to try this out but it seems like Person should have fields for this example to make sense.
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,
Sure It works! I tried it . Its contradictory to what Head first mentions in bullet points page144 .
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would you please publish the 2 classes?

Thank you
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class Person {
}

public class Employee extends Person {
private String name ;
public String getName(){
return name;
}
public void setName(String n){
name= n ;
}
}
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must be missing something. Shouldn't Person have at least a method or something? I'm not really sure what is being extended since there's nothing really there. I'm not able to be of much help but I am interested if this is something that could potentially appear on the exam.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic