March5 - Method Overloading Recursion Overloading in...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Winter 2002 APSC142 - Prof. McLeod 1 Method Overloading, Recursion Overloading in section 6.8 and recursion in section 6.7 in the textbook.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Winter 2002 APSC142 - Prof. McLeod 2 Overloading Consider our popular “ System.out.println() method: System.out.println(5); System.out.println(“Hello”); System.out.println(4E-30); System.out.println(5 > 3); System.out.println(); All along, we have used System.out.println() in this way, and it always works, regardless of the type of the argument.
Image of page 2
Winter 2002 APSC142 - Prof. McLeod 3 Overloading - Cont. So what’s going on here? Until now, we have written methods that only take one type of argument. If we call a method with an argument that does not match what the method expects, then we will get a “method not found” error. The println method is overloaded . (Heavily overloaded, in fact!)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Winter 2002 APSC142 - Prof. McLeod 4 Overloading - Cont. Somewhere in the java.io class there is a method called println(String S) ”, that accepts a String and then prints that String to the screen. In the same class, there is a method “ println(int aVal) ” that converts aVal to a String and then calls the println(String S) method. In fact, if you look up the Java documentation for the println method used as in “ System.out.println() ”, you get the following methods - all in the same class!
Image of page 4
Winter 2002 APSC142 - Prof. McLeod 5 Overloaded println() Methods public void println() public void println(boolean x) public void println(char x) public void println(int x) public void println(long x) public void println(float x) public void println(double x) public void println(char x[]) public void println(String x) public void println(Object x)
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Winter 2002 APSC142 - Prof. McLeod 6 Overloaded println() Methods - Cont.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern