方法的重载-JAVA-2021-01-07-01

package com.user.test;
//重载方法
public class OverLoadTest {
     
	public static void main(String[] agrs) {
     
		OverLoadTest a = new OverLoadTest();
		int a1 = a.mOL(2);
		System.out.println("2的平方:"+a1);
		int a2 = a.mOL(2, 3);
		System.out.println("2乘以3等于:"+a2);
		char a3 = a.mOL('e');
		System.out.println("返回CHAR:"+a3);
		int a4=a.max(10, 11);
		System.out.println("返回10与11的最大值:"+a4);
		double a5 = a.max(3, 7);
		System.out.println("返回3月7的最大值:"+a5);
		double a6 = a.max(11, 12, 13);
		System.out.println("返回三个数的最大值:"+a6);
	}

	public int mOL(int a) {
     
		return a * a;
	}

	public int mOL(int a, int b) {
     
		return a * b;
	}

	public char mOL(char a) {
     
		return a;
	}

	public int max(int a, int b) {
     
		return (a > b) ? a : b;
	}

	public double max(double a, double b) {
     
		return (a > b) ? a : b;
	}

	public double max(double a, double b, double c) {
     
		double max = (a > b) ? a : b;
		return (max > c) ? max : c;
	}

}

控制台输出:

2的平方:4
2乘以3等于:6
返回CHAR:e
返回1011的最大值:11
返回37的最大值:7.0
返回三个数的最大值:13.0

你可能感兴趣的:(java,java)