person.java代码如下:

package cn.itcast.demo;

public class person {

private String name;
private int age;


public person(String name, int age) {
super();
this.name = name;
this.age = age;
}

public person() {
super();
// TODO Auto-generated constructor stub
}

public String getName() {// the default is null
return name;
}
public int getAge() {
return age;
}
public void setAge(int age) {// the default is 0
this.age = age;
}
public void setName(String name) {
this.name = name;
}

}

 

PersonTest.java代码如下:

package cn.itcast.demo;

public class PersonTest {

/**
*
@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
person p1 = new person();

person p2 = new person("zhangsan",18);
//p1.setAge(age)

System.out.println(p2.getAge());
System.out.println(p1.getAge());
System.out.println(p1.getName());
}
}


解析:关于super(); 这个函数应该是父类中的构造方法,这个我还没有弄懂,先到这,以后有机会再补充上来。



相关文章:

  • 2021-04-12
  • 2022-12-23
  • 2022-01-14
  • 2022-02-17
  • 2021-07-13
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
猜你喜欢
  • 2021-10-17
  • 2021-10-09
  • 2021-11-17
  • 2021-11-26
  • 2022-01-22
相关资源
相似解决方案