继承关系中的this

继承关系中的this,第1张

继承关系中的this

学到了 总是忘记 记录一下

父类:

public class baseServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String method = req.getParameter("method");

        
        Class clazz = this.getClass();
}

子类:

@WebServlet("/oa/DeptServlet")
public class DeptServlet extends baseServlet {}

父类中的this.getClass()中的this指的是调用方法子类 寻找子类的service方法 没有 去父类中寻找在子类中调用的此service方法 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5608956.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存