100天代码提升计划-第6天
前言
今天是星期六,学习与不学习也一直在我的脑海里做斗争,学习与不学习都有各自的理由,最终依旧选择学习,因为害怕一旦自己停下来就变得懒惰,变得懈怠,无论自己学一节课还是半节课也要坚持学下去。加油
!!!
正文
静态static关键字描述
一旦使用static关键字那么内容不属于自己属于类
package Demo02; public class Demo01Static { public static void main(String[] args) { Student one =new Student("张三",23); one.room ="101教室"; System.out.println("姓名:"+one.getName()+",年龄:" +one.getAge()+",教室:"+one.room+",学号:"+one.getId()); Student two =new Student("李四",34); System.out.println("姓名:"+two.getName()+",年龄:" +two.getAge()+",教室:"+two.room+",学号:"+two.getId()); } }
package Demo02; public class Student { private String name;//姓名 private int age;//年龄 static String room;//所在教室 private int id; private static int jsq=100; public Student(){ this.id=++jsq; } //有参构造 public Student(String name, int age) { this.name = name; this.age = age; this.id=++jsq; } //全参构造 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; } }

浙公网安备 33010602011771号