package com.StaticDemo; public class Test1 { public static void main(String[] args) { //通过案列理解变量类型的应用场景 User u1 =new User(); User u2 =new User(); User u3 =new User(); User u4 =new User(); System.out.println(User.number); } }
package com.StaticDemo; public class User { //类变量 public static int number; //构造器 public User(){ // User.number++; // 在同一个类中访问自己的类变量才可以不写类名 number++; } }
标签:场景,变量,案列,number,User,new,public From: https://www.cnblogs.com/Karl-hut/p/17438216.html