欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java,

来源: javaer 分享于  点击 35195 次 点评:58

java,


static关键字修饰属性或者方法,该属性或者方法属于整个类的,而不是属于对象的,用类.属性或者类.方法来调用
public class Test {
public static void main(String[] args) {
Student stu1=new Student();
stu1.name="张三";
//stu1.i=2;
Student.i=2;
Student stu2=new Student();
stu2.name="李四";
//stu2.i=3;
Student.i=3;
stu1.show();//输出i =3
stu2.show();//输出i=3
}

}

class Student{
String name;
static int i=0;
public void show(){
System.out.println(name+"=="+i);
}
}

相关文章

    暂无相关文章
相关栏目:

用户点评