其他分享
首页 > 其他分享> > 构造方法与重载

构造方法与重载

作者:互联网

//构造方法与重载
//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("你","你");
}

标签:构造方法,text,System,text2,text1,重载,new,public
来源: https://blog.csdn.net/sksjxx/article/details/123095180