zoukankan      html  css  js  c++  java
  • 032_面向对象_05_程序执行过程的内存分析_02

    一、实例代码  

    package edu.aeon.test;
    /**
     * [说明]计算机类
     * @author aeon
     */
    public class Computer {
        /**计算机品牌*/
        public String brand;
        /**计算机cpu速度*/
        public int cpuSpeed;
    }
    package edu.aeon.test;
    /**
     * [说明]学生类
     * @author aeon
     * 类包括静态的属性和动态行为
     */
    public class Student {
        /**学生证号*/
        private  int stuId;
        /**学生姓名*/
        private String stuName;
        /**学生性别 0(false)-女  1(true)-男*/
        private boolean sex;
        /**学生电脑*/
        private Computer computer;
    /**
     * 动态行为:学习    
     */
     public void stard(){
        System.out.println(stuName+"正在学习!"); 
     }
     public static void main(String[] args) {
        /**创建学生对象(实例)*/
        Student student=new Student();
        System.out.println("==================默认初始化==================");
        System.out.println("学生证号:"+student.stuId);
        System.out.println("学生姓名:"+student.stuName);
        System.out.println("学生性别:"+student.sex);
        student.stard();
        System.out.println("==================程序初始化==================");
        student.stuId=10010;
        student.stuName="张三";
        student.sex=true;
        System.out.println("学生证号:"+student.stuId);
        System.out.println("学生姓名:"+student.stuName);
        System.out.println("学生性别:"+(student.sex==true?"男":"女"));
        student.stard();
        
        
        Computer computer=new Computer();
        computer.brand="联想";
        student.computer=computer;
        System.out.println(student.computer.brand);
     }
    }

    二、内存分析图

      

    如有任何疑问可联系邮箱: 给我发邮件、或直接联系QQ:1584875179 || 点返回首页

  • 相关阅读:
    在家工作,10招助你效率、生活两不误
    SQL Server智能感知如何更新
    博客园文章《我记录,故我在》读后感
    Python 协程
    Python 用多线程上传和下载文件
    Python 变量交换
    Python 将文件重新命名
    Python ftplib模块
    Python ftplib模块
    Python 函数作为返回值
  • 原文地址:https://www.cnblogs.com/aeon/p/9951570.html
Copyright © 2011-2022 走看看