/**
* @author JoeZhou
*/
public class Person {
public int id = 1;
String name = "张三";
static int age = 23;
private String gender = "女";
}
复制代码
源码:
@Test
public void instance(){
// 变量类型 变量名 = new 构造器();
Person zhaosi = new Person();
System.out.println(zhaosi);
}
@Test
public void changeForNoStaticField(){
Person zhaosi = new Person();
Person liuneng = new Person();
zhaosi.id = 50;
System.out.println(liuneng.id);
}
@Test
public void changeForStaticField(){
Person zhaosi = new Person();
Person liuneng = new Person();
// 静态属性不属于某个实例,而是属于这个模板
Person.age = 50;
System.out.println(Person.age);
}
复制代码
练习:02001-6
What is required at line 5 in class SomeApp to use the process method of BitUtils?
package util;
public class BitUtils {
private static void process(byte[] b) {}
}
// 5
package app;
public class SomeApp {
public static void main(String[] args) {
byte[] bytes = new byte[256];
// insert code here
}
}
复制代码
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils.*; process(bytes);
F. SomeApp cannot use the process method in BitUtils.