Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt about classes and types  RSS feed

 
Matheus Mew
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Head first jsp e servlets says something like:

ABSTRACT CLASS Person
- String getName()
- void setName(String)

CLASS Employee
- int getEmpID()
- void setEmpID(int)

In the jsp:

And the servlet that it would create is something like:
Person person = new Employee();

But how would it work ?? how would it knows about the setEmpID method ? Would it do an cast ? or reflection ??

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how you are going to use it. If you are going to access the variable in scriplet code, it will not know about non-Person methods. It's just Java, afetr all.

JSP actions and the EL, on the other hand, use reflection.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!