第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.静态代码块

 

 

posted @ 2020-02-26 15:49  Curedfisher  阅读(142)  评论(0编辑  收藏  举报