ch04 - Java Programming Fourth Edition Chapter 4 More...

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

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 4 More Object Concepts
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
Java Programming, Fourth Edition 2 Objectives • Understand blocks and scope • Overload a method • Learn about ambiguity • Send arguments to constructors • Overload constructors • Learn about the this reference
Background image of page 2
Java Programming, Fourth Edition 3 Objectives (continued) • Use static variables • Work with constants • Use automatically imported, prewritten constants and methods • Use the explicitly imported prewritten class GregorianCalendar
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
Java Programming, Fourth Edition 4 Understanding Blocks and Scope • Blocks – Use opening and closing curly braces – Can exist entirely within another block or entirely outside and separate from another block – Can not overlap – Types • Outside or Outer blocks • Inside or Inner blocks • Nested
Background image of page 4
Java Programming, Fourth Edition 5 A Method with Nested Blocks
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
Java Programming, Fourth Edition 6 Understanding Blocks and Scope (continued) • Scope – Portion of program within which you can refer to a variable – Comes into scope • Variable comes into existence – Goes out of scope • Variable ceases to exist
Background image of page 6
Java Programming, Fourth Edition 7 Understanding Blocks and Scope (continued) • Redeclare variable – Cannot declare same variable name more than once within block – Illegal action
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
Java Programming, Fourth Edition 8 The invalidRedeclarationMethod()
Background image of page 8
Java Programming, Fourth Edition 9 Understanding Blocks and Scope (continued) • Override – Variable’s name within method in which it is declared • Takes precedence over any other variable with same name in another method – Locally declared variables • Always mask or hide other variables with same name elsewhere in class
Background image of page 9

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

View Full Document Right Arrow Icon
Java Programming, Fourth Edition 10 The OverridingVariable Class
Background image of page 10
Java Programming, Fourth Edition 11 Output of the OverridingVariable Application
Background image of page 11

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

View Full Document Right Arrow Icon
Java Programming, Fourth Edition 12 Overloading a Method • Overloading – Using one term to indicate diverse meanings – Writing multiple methods with same name but with different arguments – Compiler understands meaning based on arguments used with method – Convenience for programmers to use one reasonable name • For tasks that are functionally identical • Except for argument types
Background image of page 12
Java Programming, Fourth Edition 13 The calculateInterest() method with two double arguments
Background image of page 13

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

View Full Document Right Arrow Icon
Java Programming, Fourth Edition 14 Learning About Ambiguity • If application contains just one version of method
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 41

ch04 - Java Programming Fourth Edition Chapter 4 More...

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

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