**编写类Student,包含属性学号、姓名、年龄,请如何实现:记录 实例化多少了对象 PS:考虑下静态变量,在哪里赋值然后加1**
public class Lxjilu { static int count=0; //定义全局变量 // int id; // String name; // int age; // public Lxjilu(int id,String name,int age){ //构造有参函数 // this.id=id; //变量初始化 // this.name=name; // this.age=age; // count++; //每次执行Lxjilu方法count+1 // } public static void main(String[] args) { new student(002,"李四",30); new student(003,"张三",20); System.out.println(count); } }//另一种写法,此方法写在主类外面,调用主类变量需"加类名.*" class student{ int id; String name; int age; public student(int id,String name,int age){//构造有参函数 this.id=id; this.name=name; this.age=age; Lxjilu.count++; //每次每次执行student方法count+1 } }静态优先级