DOC PREVIEW
UB CSE 115 - Writing Methods is a two-step process

This preview shows page 1-2-3-4-5-6 out of 17 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Notes from Week 5Writing Methods is a two-step processWriting the method (defining the method)Method Writing - Method SignatureSlide 5Slide 6Method Writing - Method BodyMethod CallingStringsPrinting information to the console (screen)InheritanceGeneralization RelationshipInheritance BasicsAccessors & MutatorsMethod OverloadingAccessors (get methods)Mutators (set methods)Notes from Week 5CSE 115 Spring 2006February 13, 15 & 17, 2006Writing Methods is a two-step processGive definition of how method will perform – write the method.When we want the work of the method to actually get done – the method call.Writing the method (defining the method)Specify Method Signature:VisibilityReturn typeName for methodParameter listSpecify Method Body:Code that method must execute to perform required task.Method Writing - Method SignatureVisibility public is best if you want anyone to be able to call your methods.Return typevoid if nothing is returned.If something is returned, need to use keyword return in method body to indicate value being returned.Method Writing - Method SignatureGive the method a name (mind the rules)Method is an identifierStyle: first letter lower case, each subsequent word capitalized.Eg) myFirstMethodMethod Writing - Method SignatureParameters (formal parameters)Specify for eachTypeNameWhy do parameters get a name in the method definition?So we can refer to them inside the method body.Method Writing - Method BodyCode that is executed when method is called.Need additional variables inside the method?Create a local variable.Local variables are only accessible from inside the method body.Method CallingMethod call:instanceName.methodName();Pass in actual values for each of the required parameters. (actual parameters)Do something with the return type if there is one. (What if you don’t?)StringsList of CharactersCharacters are any single letter, digit, or symbolIn code:”Strings are surrounded by quotes”Printing information to the console (screen)System.out.println(”Some text.”);InheritanceCan be viewed as a specialization of a superclass.Can be viewed as generalizing several subclasses into a superclass.Generalization Relationship“is a” relationshipThere is a superclass and a subclassIn code:public class ClassB extends ClassA {}Inheritance BasicsWhen a subclass extends a superclass, the subclass inherits all public capabilities (methods) of the superclass and they remain public in the subclass.When a class has a superclass and we create an instance of the subclass, the no-argument constructor of the superclass is called automatically from the constructor of the subclass.Accessors & MutatorsMethods inside of a class that work with the instance variables to provide the value of the instance variable and to change the value of the instance variable respectfully.Method OverloadingTwo methods can have the same name only if they differ in number and/or type of parameters.Constructors can be overloaded too!Accessors (get methods)Access the value of an instance variable.public TypeOfProperty getProperty(){return _instanceVariableName;}Mutators (set methods)Change the value of an instance variable.public void setProperty (TypeOfProperty newValue) {_instanceVariableName =


View Full Document

UB CSE 115 - Writing Methods is a two-step process

Download Writing Methods is a two-step process
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Writing Methods is a two-step process and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Writing Methods is a two-step process 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?