Download presentation
Presentation is loading. Please wait.
1
CSE 115 September 29 – October 3, 2008
2
Announcements Lab 5 posted
Note schedule of labs for the next two weeks No classes meet Tuesday Lab 5 due the day before your lab meets during the week of October 13th Exam 3 is October 17th Check UBLearns for grades on Exam 1 and Labs 1 & 2.
3
Lesson Plan Building graphical programs Writing methods
15
Methods Realization in Java code of the capabilities of an object
Methods are made up of a method header and a method body Method header: public returnType methodName (parameter list)
16
Method Header Details public – accessible from all parts of program
returnType – type of information returned from the method; void is return type if nothing is returned methodName – identifier; style is first letter lower case and first letters of subsequent words upper case parameter list – possibly empty list of information needed for the method to complete its tasks
17
Parameters If a parameter is needed, inside the () you see:
type parameterName Where type is the type of the parameter and parameterName is an identiifier we will use to refer to the parameter inside the method body. Style is the same as method names and local variables. In fact, you could consider a parameter as a special type of local variable. It is assigned its initial value during the method call and its scope is only within the method body.
18
Method body Enclosed inside { }
Contains the code that performs the actions of the method.
19
Important Note In order for methods to execute (the code inside the body to actually run), we need to make sure that they are called. Recall calling methods: objectReference.methodName(); We need to insert an argument (value) into the () if the method requires one.
20
Keyword this The keyword this is a self-reference and is used from within the class to refer to itself. It is a reference, similar to the references we create and name ourselves, except it refers to the object that will be created when the class is created. Another way to think of it is to replace the word this with self inside the code.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.