Eternal Nightmare
March 28, 2024, 11:39:40 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Breaking News: We Are Growing Fast. Keep Up The Good Work Guys
 
  Home Help Search Arcade Staff List Login Register  

what is method overloading in java...

Pages: [1]
  Print  
Author Topic: what is method overloading in java...  (Read 226 times)
0 Members and 1 Guest are viewing this topic.
sam2112
Commander
*

OWned +0/-0
Offline Offline

Posts: 357


« on: September 03, 2010, 06:28:02 am »

In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java implements polymorphism.
// Demonstrate method overloading.
class OverloadDemo {
void test() {
System.out.println("No parameters");
}
// Overload test for one integer parameter.
void test(int a) {
System.out.println("a: " + a);
}
// Overload test for two integer parameters.
void test(int a, int b) {
System.out.println("a and b: " + a + " " + b);
}
// overload test for a double parameter
double test(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
class Overload {
public static void main(String args[]) {
OverloadDemo ob = new OverloadDemo();
double result;
// call all versions of test()
ob.test();
ob.test(10);
ob.test(10, 20);
result = ob.test(123.2);
System.out.println("Result of ob.test(123.2): " + result);
}
}

___________

SEO Services | Search Engine Optimization
Report Spam   Logged

Share on Facebook Share on Twitter

henrystrange
Starter
*

OWned +0/-0
Offline Offline

Posts: 27


« Reply #1 on: November 21, 2011, 07:12:18 am »

{
   public static void main(String[] args)

  {

   functionOverload obj = new functionOverload();

   obj.add(1,2);
   obj.add(\"Life at \", \"?\");
   obj.add(11.5, 22.5);

   }
}

class functionOverload
 {
   /*  void add(int a, int b)             // 1 - A method with two parameters
     {

        int sum = a + b;
        System.out.println(\"Sum of a+b is \"+sum);

     }    */

     void add(int a, int b, int c)       {

        int sum = a + b + c;
        System.out.println(\"Sum of a+b+c is \"+sum);

     }

     void add(double a, double b)             {

        double sum = a + b;
        System.out.println(\"Sum of a+b is \"+sum);
     }

     void add(String s1, String s2)

     {
       String s = s1+s2;
       System.out.println(s);
     }
}




Generative Leadership
Report Spam   Logged
david
Hero
*

OWned +0/-0
Offline Offline

Posts: 459


« Reply #2 on: May 22, 2012, 10:34:31 am »

Another good source for recommendations on geology books  is trade journals, which may include book reviews. People can also research reviews online, looking for reviews on geology sites and reading the reviews on websites which sell books  and invite user feedback. Other things which can be used to guide a purchase include searching for specific authors, such as experts in a particular field of geology, or specific publishers who are well known for producing good geology books. As a more general rule, university presses tend to produce the most high quality geology books, although they can get highly technical. Another source for geology books is the bibliography in other books; if a book is particularly interesting or useful, books listed in the bibliography as sources and inspiration may also be good choices to read.
camisetas futbol | soccer kit | soccer shirts



« Last Edit: August 12, 2013, 11:38:45 am by david » Report Spam   Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy