This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Why an inner class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why an inner class?" Watch "Why an inner class?" New topic
Author

Why an inner class?

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
This is one of the versions of BeeServlet from the CattleDrive assignments on Servlets. I'm planning on using this as the model for my code, but I'm wondering why Default is coded as an inner class. (Though I'm copying, I figure I should still know why I'm doing what I'm doing!)

package com.javaranch.drive ;

import com.javaranch.common.* ;

public class BeeServlet extends ActionServlet
{

private class Default implements ActionHandler
{
public void doAction( ServletData servletData )
{
servletData.setAttribute( "text" , "MVC2-buzz-buzz ..." );
forward( "/bee.jsp" , servletData );
}
}

public void init()
{
addActionHandler( "default" , new Default());
}

}

If Default was moved outside of BeeServlet, would it make any difference?
Choon-Chern Lim
Ranch Hand

Joined: Aug 29, 2005
Posts: 74
http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Thanks Choon-Chern. That's a useful link!
 
wood burning stoves
 
subject: Why an inner class?
 
Similar Threads
Instructor's solution to servlets 3-a ?
Bogging down a bit.....
Servlets 4a blocked
cookie questions
Question about MVC2 BeeServlet