- 模拟Servlet的service和doGet方法
HttpServlet.java
public class HttpServelt {
public void service(){
System.out.println("HttpServlet.service()");
this.doGet();
}
public void doGet(){
System.out.println("HttpServlet.doGet()");
}
}
MyServlet.java
public class MyServlet extends HttpServelt {
@Override
public void doGet() {
System.out.println("MyServlet.doGet()");
}
}
TestServlet.java
public class TestServlet {
public static void main(String[] args) {
HttpServelt s = new MyServlet();
s.service();
}
}
- 运行结果
- 内存分析
HttpServlet.java public class HttpServelt { public void service(){ System.out.println("HttpServlet.service()"); this.doGet(); } public void doGet(){ System.out.println("HttpServlet.doGet()"); } } MyServlet.java public class MyServlet extends HttpServelt { @Override public void doGet() { System.out.println("MyServlet.doGet()"); } } TestServlet.java public class TestServlet { public static void main(String[] args) { HttpServelt s = new MyServlet(); s.service(); } }
- 运行结果
- 内存分析