Lec 08 Methods Revisited

Lec 08 Methods Revisited - FIT1002 Computer Programming...

Info iconThis preview shows pages 1–4. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: FIT1002 Computer Programming Module 8 Methods Revisited www.monash.edu.au FIT1002 Computer Programming Module 8 Methods Revisited COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice. The authors acknowledge that material in these modules has been adapted from slides produced by Lewis, DePasquale and Chase for Java Foundations: Introduction to Programming and Data Structures , Addison-Wesley, 2007 Before the beginning of this lecture, students should be familiar with: The concept of breaking down code into its different functions The basic structure of a class definition Before the beginning of this lecture, students should have read over: Chapter 5.4 of Lewis et. al. Assumed Knowledge 2 3 Objectives Revise the concept of a method Write methods which return values Write methods which accept parameters Understand the role of accessors and mutators Write methods which return computed values Overload methods when necessary FIT1002 Computer Programming Module 8 Methods Revisited Methods (Revision) Groups of statements that are given their own name Can be given data to use in performing their work Can return single items of data A method declaration specifies code to be executed when the method is invoked (called) 4 Method Example (Revision) public void showOptions( ) { System.out.println("1. Add new student record to system"); System.out.println("2. Display existing student record"); System.out.println("3. Enrol student into a subject"); System.out.println("4. Save all data and exit program"); } public void displayMenu() { showOptions( ); } Sample method invocation (cal ) to cause this method to be executed. 5 Method Control Flow (Revision) myMethod(); myMethod compute If the called method is in the same class, only the method name is needed... 6 FIT1002 Computer Programming Module 8 Methods Revisited Method Control Flow (Revision) The called method is often part of another class or object... doIt helpMe helpMe(); obj.doIt(); main Class A Class A Class B Class B obj obj is a is a variable of variable of type type B in in main() main() 7 In past modules you have been introduced to the design of methods, however they have been mainly static methods For example: public static void main() public static void introduction() Static methods are ones we can use in a class without needing to instantiate objects they are just referenced by the class and method name Static methods are limited however Static Methods 8 Static methods cannot reference instance variables because instance variables don't exist until an object...
View Full Document

Page1 / 19

Lec 08 Methods Revisited - FIT1002 Computer Programming...

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

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