- class Person
- {
- private string name;
- private int age;
- Person()
- {
- System.out.println("A:name="+name+",,age="+age);
- }
- Person(String n)
- {
- name = n;
- System.out.println("B:name="+name+",,age="+age);
- public void setName(String n)
- {
- name = n;
- }
- public String getName()
- {
- return name;
- }
- }
- Person(String n,int a)
- {
- name = n;
- age = a;
- System.out.println("C:name="+name+",,age="+age);
- }
- }
- class PersonDemo
- {
- public static void main(String[] args)
- {
- //对应不同的初始化方式。
- //Person p1 = new Person();
- Person p2 = new Person("lisi");
- p2.setName("libushi");
- System.out.println(p2.getName());
- //Person p3 = new Person("wangwu",10);
- }
- }
复制代码
这段程序里,哪些是局部变量哪些是成员变量啊? |
|