Powered by Blogger.
Showing posts with label overloding all details. Show all posts
Showing posts with label overloding all details. Show all posts

Java Overloading Methods and Program Solution

Definition of Overloading Methods:-

We can declare several methods of same name in a class, which is known as methods overloading. For overloading methods argument lists must be different and return type can be different. In the following code, there are four methods of same name with different argument, which is an example of overloading methods.

Overloading Methods Program:-

 public class ABC{
    int a, b, c;

    public void setValue(){
       a=2;
       b=4;
       c=6;
    }

    public void setValue(int a){
       this.a=a;
       b=4;
       c=6;
    }

    public void setValue(int a, int b){
       this.a=a;
       this.b=b;
       c=6;
    }

    public int setValue(int a, int b, int c){
       this.a=a;
       this.b=b;
       this.c=c;
       int z = a+b+c;
       return z;
    }
  }