overloaded methods
play

Overloaded Methods AP Computer Science - Unit Four Overloaded - PowerPoint PPT Presentation

Lesson 35: Overloaded Methods AP Computer Science - Unit Four Overloaded Methods Definition Overloading is when a program has more than one method with the same name. AP Computer Science - Unit Four Overloaded Methods Example - String


  1. Lesson 35: Overloaded Methods AP Computer Science - Unit Four

  2. Overloaded Methods Definition Overloading is when a program has more than one method with the same name. AP Computer Science - Unit Four

  3. Overloaded Methods Example - String method w.substring (4); w.substring (2, 5); Both of these methods do the same thing - return a part of a larger String. But, they use a different set of parameters. AP Computer Science - Unit Four

  4. Overloaded Methods Overloading - Basic Idea Each method does the same kind of operation. Does that operation on different sets of data. AP Computer Science - Unit Four

  5. Overloaded Methods How do you tell the methods apart? Signature - Number and types of parameters public static int sum(int a[]) public static int sum (int a, int b) AP Computer Science - Unit Four

  6. Overloaded Methods Signature does not include the return type public static int add(int a) public static double add(int a) Since the parameters are exactly the same type Java can't tell these two methods apart. AP Computer Science - Unit Four

  7. Overloaded Methods Now you try it: Write two overloaded methods max. The first should find the max of two int parameters. The second should find the max of three int parameters. AP Computer Science - Unit Four

  8. Overloaded Methods Why would we overload? We have already used this: System.out.print ("Howdy"); System.out.print (56); More efficient AP Computer Science - Unit Four

  9. Overloaded Methods Polymorphism Overloading is an example of polymorphism Polymorphism allows values of different data types to be handled using a uniform interface In English: Lets us have one name to describe many things AP Computer Science - Unit Four

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend