Method Overload example
package com.ram; class Sum{ public int add(int x, int y){ return (x + y); } public int add(int x, int y, int z){ return (x + y + z); } public double add(int x, double y){ return (x + y); } } public class OverloadExample { public static void main(String[] args) { Sum sum = new Sum(); System.out.println(sum.add(10, 20)); System.out.println(sum.add(10, 20, 30)); System.out.println(sum.add(10, 10.50)); } }
Execute OverloadExample class and you get the below output:
30
60
20.5
30
60
20.5
No comments:
Post a Comment