java——构造方法重载

 1 class Person
 2 {
 3 private String name ;
 4 private int age ;
 5 public Person()
 6 {
 7 }
 8 public Person(String n,int a)
 9 {
10 name = n;
11 age = a;
12 System.out.println(name+age) ;
13 }
14 public String talk()
15 {
16 return "我是: "+name+",今年: "+age+"岁" ;
17 }
18 }
19 
20 public class Test
21 {
22 public static void main(String[] args)
23 {
24 Person p = new Person() ;
25 System.out.println(p.talk()) ;
java-构造方法重载

 

posted @ 2017-03-04 16:30  DevOps_QXW  阅读(1510)  评论(1编辑  收藏  举报