- class plus{
- static int add(int a,int b)
- {
- return a+b;
- }
- static int add(int a,int b,int c)
- {
- return a+b+c;
- }
- }
- class Overloading1
- {
- public static void main(String[] args)
- {
- //access the add method with 2 param from class plus,
- //pass 2 arguments and print the return value
- System.out.println(plus.add(10,10));
- //access the add method with 3 param from class plus,
- //pass 3 arguments and print the return value
- System.out.println(plus.add(10,10,10));
- }
- }
It will produce the following results:
20
30
Comments
Post a Comment