Java基础之static类
/**
-
测试static类
*/
public class Test069 {
int id;
String name;
String pwd;//密码
static String company=“北京尚学堂”;//公司名
public Test069(int id,String name,String pwd){
this.id=id;
this.name=name;
this.pwd=pwd;
}
public void login(){//非静态方法,非静态可以调用静态,静态不可以调用非静态
printCompany();
System.out.println(company);
System.out.println(“登录:”+name);
}
public static void printCompany(){//静态方法,带static
//login(); 调用非静态成员,编译就会报错
System.out.println(company);
}public static void main(String[] args) {
Test069 t=new Test069(1001,“李志鹏”,“10001532”);
Test069.printCompany();
Test069.company=“北京阿里巴巴”;
Test069.printCompany();
t.login();
}
}