//构造方法与重载 //1.构造函数:没有返回值类型 方法名和类名一致 //访问修饰符必须是public public text(int text1,int text2){ System.out.println(Math.max(text1,text2)); } //重载: //存在同一个类类当中 //方法名一致、 //参数列表不一致 public text(double text1,double text2,double text3){ System.out.println(text1*text2*text3); } public text(String str1, String str2){ System.out.println(str1.equals(str2)?"相等":"不相等"); }
public static void main(String[] args) { text text = new text(1,2); text text2 = new text(1,3,4); text text3 = new text("你","号"); text text4 = new text("你","你"); }