March5 - Winter 2002 APSC142 Prof McLeod 1 Method...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Winter 2002 APSC142 - Prof. McLeod 1 Method Overloading, Recursion • Overloading in section 6.8 and recursion in section 6.7 in the textbook. 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. 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!) 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! 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) Winter 2002 APSC142 - Prof. McLeod 6 Overloaded...
View Full Document

This note was uploaded on 12/01/2010 for the course APPLIED SC 142 taught by Professor Professorstansimmons during the Winter '10 term at Queens University.

Page1 / 20

March5 - Winter 2002 APSC142 Prof McLeod 1 Method...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online