标签:[] sys oop 多态 extend http src ima alt
HttpServlet.java
package cn.bjsxt.oop.polymorphism.myServlet;
public class HttpServlet {
public void service(){
System.out.println("HttpServlet.service()");
this.doGet();
}
public void doGet(){
System.out.println("HttpServlet.doGet()");
}
}
MyServlet.java
package cn.bjsxt.oop.polymorphism.myServlet;
public class MyServlet extends HttpServlet {
public void doGet(){
System.out.println("MyServlet.doGet()");
}
}
Test.java
package cn.bjsxt.oop.polymorphism.myServlet;
public class Test {
public static void main(String[] args) {
HttpServlet s = new MyServlet();
s.service();
}
}
输出结果:
HttpServlet.service()
MyServlet.doGet()
内存分析如下:
其中this指向最外面的对象
标签:[] sys oop 多态 extend http src ima alt
原文地址:https://www.cnblogs.com/pallcard-LK/p/8973977.html