lec6 - 1.00 Lecture 6 Methods and Scope Reading for next...

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

View Full Document Right Arrow Icon
1.00 Lecture 6 Methods and Scope Reading for next time: Big Java: sections 2.1-2.5 Java Methods Methods are the interface or communications between program components They provide a way to invoke the same operation from many places in your program, avoiding code repetition They hide implementation details from the component using the method Variables defined within a method are not visible to users of the method; they have local scope within the method. The method cannot see variables in the component that calls it either. There is logical separation between the two, which avoids variable name conflicts.
Background image of page 1

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

View Full DocumentRight Arrow Icon
{ return result;} double getDensity(double bw, double bc) // Method makes its own copy // of arguments bw and bc Double result= bw/bc; Passing Arguments (from last time) main(…){ double boxWeight= 50; Communi- double boxCube=10; String boxID= “Box A”; cation only double density=getDensity via arg list, return value (boxWeight, boxCube); Arguments matched by Return value Argument 1 Argument 2 position Assume method is written first: can’t know main() vars Method Exercise: step 1
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/29/2011 for the course CIVIL 1.00 taught by Professor Georgekocur during the Spring '05 term at MIT.

Page1 / 6

lec6 - 1.00 Lecture 6 Methods and Scope Reading for next...

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

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