zoukankan      html  css  js  c++  java
  • Java多态内存分析

    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指向最外面的对象

  • 相关阅读:
    wkhtmktopdf
    linux命令行抓取网页快照
    ubuntu 固定静态IP
    $http questions
    generate_scripts
    network
    IT_Qestion
    day03
    day02
    day01
  • 原文地址:https://www.cnblogs.com/pallcard-LK/p/8973977.html
Copyright © 2011-2022 走看看