Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Understand the following implementation which uses method or function overloading in Java ?class Addition{ ??void add(int a,int b){ ??System.out.println(Inside add(int,int) method); ???System.out.println(a+b); ???} ??void add(int

Understand the following implementation which uses method or function overloading in Java
?class Addition{
??void add(int a,int b){
??System.out.println(Inside add(int,int) method);
???System.out.println(a+b);
???}
??void add(int a,int b,int c){
??System.out.println(Inside add(int,int,int) method);
???System.out.println(a+b+c);
???}
??void add(float a,float b){
??System.out.println(Inside add(float,float) method);
???System.out.println(a+b);
???} ??
?public static void main(String args[]){
? ?Addition obj=new Addition ();
? ?obj.sum(10,10,10);
? ?obj.sum(20,20);
? ?obj.add(10.5,10.5);
??}
?}
Output:
Inside add(int,int,int) method?
30
Inside add(int,int) method
40
Inside add(float,float) method?
21
Now predict the output of the program below. Also, state the advantages of function overloading
class Calculator{
??void sum(int a,long b){
System.out.println(Inside sum(int,long) method);
System.out.println(a+b);
}
??void sum(float a,long b){
???System.out.println(Inside sum(float,long) method);?
System.out.println(a+b);
}
??public static void main(String args[]){
?? ?Calculator obj=new Calculator ();
? ?obj.sum(20,20);
?? ?obj.sum(20.5,20);
??}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago