你好- public class Person
- {
- private String name="lisi";//默认初始化name值为null,显示初始化为lisi
- private int age=10;//默认初始化age值为0,显示初始化为10
- //构造函数初始化
- Person(String name,int age)
- {
- this.name=name;
- this.age=age;
- }
-
- public static void main(String[] args)
- {
- Person p=new Person("zhangsan",20); //调用构造函数初始化
- }
- }
复制代码 |