public class Human{ String name; char sex; int age; Human(String n){ name=n; } Human(String n,char s){ name=n; sex=s; } Human(String n,char s,int a){ name=n; sex=s; age=a; } public static void main(String[] args){ Human human1=new Human("XXX"); Human human2=new Human("XXX",'X'); Human human3=new Human("XXX",'X',00); System.out.println("姓名"+"性别"+"年龄"); System.out.printf("%8s,%4c,%4d",human1.name,human1.sex,human1.age); System.out.println(); System.out.printf("%8s,%4c,%4d",human2.name,human2.sex,human2.age); System.out.println(); System.out.printf("%8s,%4c,%4d",human3.name,human3.sex,human3.age); } }
构造方法的重载
最新推荐文章于 2024-08-30 22:17:40 发布