publicclassPersonTest{ publicstaticvoidmain(String[] args){ //创建类的对象:new + 构造器 Person p = new Person(); p.eat(); Person p1 = new Person("Tom"); System.out.println(p1.name); } }
classPerson{ //属性 String name; int age; //构造器 publicPerson(){ System.out.println("Person()....."); } publicPerson(String n){ name = n; } // publicPerson(String n,int a){ name = n; age = a; }