public class Test1 {
public static void main(String[] args) {
//静态属性的调用-----"类名."
System.out.println(Chinese.country);
//实例变量的调用-----new一个对象,”引用."
Chinese c = new Chinese("123456789","零零1");
System.out.println(c.IDcard);
System.out.println(c.name);
}
}
//定义一个类:中国人
class Chinese {
//定义该类中有哪些变量
//身份证号:每一个人都有一个身份证号(实例变量)
String IDcard;
//人名:一个人一个姓名(实例变量)
String name;
//国籍:每个中国人的国籍都是中国,所以用static修饰(静态变量)
static String country = "中国";
//定义该类中的方法
//无参数
public Chinese(){
}
//有参数
public Chinese(String s1,String s2){
IDcard = s1;
name = s2;
}
}