11SwitchEtcSmall

11SwitchEtcSmall - Lecture Set #11: Ternary Operator and...

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

View Full Document Right Arrow Icon
1 Lecture Set #11: Ternary Operator and Switch Method Overloading Warning ternary operator: The ?: (conditional operator) switch CMSC 131 Fal 2009 Jan Plane (adapted from Bonnie Dorr) Method Overloading c Method definition public static void f(int x, float y){ body } c prototype: public static void f(int x, float y) c signature: f(int, float ) c You can only overload methods if they have different signatures. c Implicit widening conversions are allowed c Beware of subtle problems with widening conversions CMSC 131 Fal 2009 Jan Plane (adapted from Bonnie Dorr) 1 CMSC 131 Fal 2009 Jan Plane (adapted from Bonnie Dorr) 2 The Conditional Operator c The only ternary operator (has 3 operands) c Format: c boolean-expression?expression1:expression2 c Purpose: c test to see if boolean-expression is true or false c whole expression takes on the value of expression1 when boolean-expression was true c whole expression takes on the value of expression2 when boolean-expression was false c See examples
Background image of page 1

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

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

Page1 / 3

11SwitchEtcSmall - Lecture Set #11: Ternary Operator and...

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

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