zoukankan      html  css  js  c++  java
  • 第6节 静态static关键字

    1.概述.

     2.静态static关键字修饰成员变量(也就是类属性)

    ============================================================================================================================ 

    Student.java

    package cn.itcast.day08.demo03;

    public class Student {

    private int id; // 学号
    private String name; // 姓名
    private int age; // 年龄
    static String room; // 所在教室
    private static int idCounter = 0; // 学号计数器,每当new了一个新对象的时候,计数器++

    public Student() {
    this.id = ++idCounter;
    }

    public Student(String name, int age) {
    this.name = name;
    this.age = age;
    this.id = ++idCounter;
    }

    public int getId() {
    return id;
    }

    public void setId(int id) {
    this.id = id;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    public int getAge() {
    return age;
    }

    public void setAge(int age) {
    this.age = age;
    }
    }

    ===========================================================================================================================================

    3.static关键字修饰方法.

     

     

     

     

     

     ==========================================================================================================================

    4.静态static的内存图

     ============================================================================================================================================

    5.静态代码块

     

  • 相关阅读:
    HDU 1863 畅通工程(并查集)
    HDU 1232 畅通工程
    洛谷 1162 填涂颜色 (dfs,染色法)
    HDU 2689 sort it(树状数组 逆序数)
    mod_js.so下载 转自网络
    The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    B计划 第七周
    B计划 第六周
    B计划 第五周
    B计划 第四周(开学第一周)
  • 原文地址:https://www.cnblogs.com/curedfisher/p/12367389.html
Copyright © 2011-2022 走看看