首页 » 开发 » JAVA » java常用知识:static关键字修饰成员的方法

java常用知识:static关键字修饰成员的方法

 
public class Students2{
	private String name;
	private int age;
	private int id;
	private static int idzizeng = 0;
	static String room;
	public Students2(){
		this.id = ++idzizeng;
	}
	public Students2(String name,int age){
		this.name = name;
		this.age = age;
		this.id = ++idzizeng;
	}
	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;
	}
	public int getId(){
		return id;
	}
	public void setId(int id){
		this.id = id;
	}
}
public class Test055{
	public static void main(String[] args){
		Students2 one = new Students2("王霞",19);
		one.room = "教室202";
		System.out.println("姓名:"+one.getName()+",年龄:"+one.getAge()+",教室:"+one.room+",学号:"+one.getId());
		Students2 two = new Students2("王霞2",20);
		System.out.println("姓名:"+two.getName()+",年龄:"+two.getAge()+",教室:"+two.room+",学号:"+two.getId());
	}
}

原文链接:java常用知识:static关键字修饰成员的方法,转载请注明来源!

0