正在加载图片...
构造方法重载 在 遇到许多不同 public class Student String name 不同的参数 Int age public Student( String S, int n)f 方法,亦即对 name = S 个构造方法的 public Student(Strings) this(s, 20) 本类中的其他 public Studenti this("Unknown")构造方法重载 ▪ 在进行对象实例化时可能会遇到许多不同 情况,于是要求针对所给定的不同的参数 调用各个不同的构造方法 ▪ 在一个类中同时定义若干个构造方法,亦即对 构造方法进行重载来实现 ▪ 在其中一个构造方法中引用另一个构造方法的 情况。可以使用关键字this来指代本类中的其他 构造方法 public class Student{ String name; int age; public Student(String s, int n){ name = s; age = n; } public Student(String s){ this(s, 20); } public Student(){ this("Unknown"); } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有