• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheriting from servlet

 
Bob Moranski
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a general catalog that has two class variables: protected String title = "General Catalog Page";
protected String[] itemIDs = {"jacket", "windbreaker", "shirt", "notepad", "pen"};
And the servlet will println a HTML page with title and then print out each of the content keyed by itemIDs[i]. The problem is when I try to inherit from this servlet, and override protected String title = "Clothing Catalog Page";
protected String[] itemIDs = {"jacket", "windbreaker", "shirt"};
The child servlet still displays the same content as the General Catalog servlet. Can someone please help?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variable references are resolved at compile time - they don't get looked up dynamically like methods do. So - if you call a method in the parent class, it will use the variables it was compiled with.
IMHO you have taken a wrong turn in your program design by putting these details into the servlet class. If you can move them to a Catalog class - or maybe even define a Catalog interface or Catalog abstract class, I bet you will find it easier to continue development. This will simplify your servlet and make it easier to debug.
Bill

 
Bob Moranski
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much Bill!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic