1 / 6

Methods

Methods. It’s how stuff gets done. What. Methods are blocks of code that can be called from anywhere in the program They take in a set of variables or nothing at all They can return one variable or nothing at all. Where. The methods are placed inside of the class decleration. Why.

lavender
Download Presentation

Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Methods It’s how stuff gets done

  2. What • Methods are blocks of code that can be called from anywhere in the program • They take in a set of variables or nothing at all • They can return one variable or nothing at all

  3. Where • The methods are placed inside of the class decleration

  4. Why • Re-Use: Methods provide a convenient way to re-use code. If there is a specific process that occurs repeatedly then it can be replaced at each location with a single method call • Management: Methods also provide a centralized location to define a process so it can be easily changed everywhere by changing what is inside the method. • Encapsulation: When a method has been programed by someone else, you can also use it without worrying about how it works.

  5. How • The structure for a method is as follows: public/private returnType name(input variables){ code } • public/private – whether the method is public or private • returnType – what type of variable or Object the method returns • name – the name of the variable • input variables – the variables or Objects that the method takes in • code – the code that is executed

  6. Other stuff • When primitive variables are passed into a method they are passed by copy while objects are passed by reference. • So if there is a primitive variable x passed into the method then the value will not be changed outside of the method.

More Related