ChapterFivePartIII

ChapterFivePartIII - IT108 Introduction to Methods Part III...

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

View Full Document Right Arrow Icon
IT108 Introduction to Methods – Part III George Mason University Irene Bruno, modified by Bill Pegram
Background image of page 1

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

View Full Document Right Arrow Icon
Overloading Methods Overloaded methods will have same name but different signatures (number of parameters, , order of parameters, or datatype of parameters) One can’t overload based on different return type Overloading should only be used when the various versions of the method do roughly the same thing
Background image of page 2
Overloading Methods Listing 5.3 Overloading the max Method public static double max(double num1, double num2) { if (num1 > num2) return num1; else return num2; }
Background image of page 3

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

View Full Document Right Arrow Icon
Ambiguous Invocation Sometimes there may be two or more possible matches for an invocation of a method, but the compiler cannot determine the most specific match. This is referred to as ambiguous invocation . Ambiguous invocation is a compilation error.
Background image of page 4
Ambiguous Invocation public class AmbiguousOverloading { public static void main(String[] args) { System.out.println(max(1, 2)); } public static double max(int num1, double num2) { if (num1 > num2) return num1; else return num2; } public static double max(double num1, int num2) { if (num1 > num2) return num1; else return num2; } }
Background image of page 5

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

View Full Document Right Arrow Icon
The Math Class Class constants: PI E Class methods: Trigonometric Methods Exponent Methods Rounding Methods min, max, abs, and random Methods
Background image of page 6
Rounding Methods
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 16

ChapterFivePartIII - IT108 Introduction to Methods Part III...

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

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