0% found this document useful (0 votes)
17 views3 pages

Oop Reviewer

Methods are defined inside classes and group program statements based on functionality. All programs have at least one method, the Main() method. A method contains modifiers, a return type, a name, parameters, a body, and is called on classes or objects. Methods allow passing data through parameters and returning data through the return type. Well-written methods have a single clear purpose indicated by their name.

Uploaded by

yuuushuuuu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Oop Reviewer

Methods are defined inside classes and group program statements based on functionality. All programs have at least one method, the Main() method. A method contains modifiers, a return type, a name, parameters, a body, and is called on classes or objects. Methods allow passing data through parameters and returning data through the return type. Well-written methods have a single clear purpose indicated by their name.

Uploaded by

yuuushuuuu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP REVIEWER

METHODS AND BEHAVIORS

ANATOMY OF A METHOD
 Methods defined inside classes
 Group program statements
o Based on functionality
o Called on or more times
 All programs consist of at least one method
o Main()
 User-defined method
 Required method
o public static void Main()
 public static - Modifiers
 void - Return type
 Main - Method name
 () - Parameters or arguments

 Modifiers
o Appear in method headings
o Appear in the declaration heading for classes and other class members
o Indicate how it can be accessed
o Types of modifiers
 Static
 Access

o Static Modifier
 Indicates member belongs to the type itself rather than to a specific object of a class
 Main() must include static in heading
 Members of the Math class are static
 Public static double Pow(double, double)
 Methods that use the static modifier are called class methods
 Instance methods require an object
o Access Modifiers
 public - no restrictions
 protected - limited to the containing class or classes derived from the containing class
 internal - limited to current project
 protected internal - limited to current project or classes derived from class
 private - limited to containing class

 Return Type
o Indicates what type of value is returned when the method is completed
o Always listed immediately before method name
o void
 No value being returned
o return statement
 Required for all non-void methods
 Compatible value
 Method Names
o Follow the rules for creating an identifier
 Pascal case style
 Action verb or prepositional phrase
o Example
 CalculateSalesTax()
 AssignSectionNumber()
 DisplayResults()
 InputAge()
 ConvertInputValue()

 Parameters
o Supply unique data to method
o Appear inside parentheses
 Include data type and an identifier
 In method body, reference values using identifier name
 Parameter refers to items appearing in the heading
 Arguments for items appearing in the call
 Formal parameters - (int milesTraveled, double gallonsUsed)
 Actual arguments - (289, 12,2)
o Like return types, parameters are optional

 Method Body
o Enclosed in curly braces
o Include statements ending in semicolons
 Declare variables
 Do arithmetic
 Call other methods
o Value-returning methods must include return statement

 Calling Class Methods


o Invoke a method
o Call to method that returns no value
 [qualifier].MethodName(argumentList);
o Qualifier
 Square brackets indicate optional
 class or object name
o Call to method does not include data type
o Use Intellisense
 After typing a dot, list of members pops up
 Shows Method signature(s) and description
 3D fuchsia colored box - methods
 aqua colored box - fields

o Predefined Methods
 Extensive class library
 Console class
 Write() - overloaded
 WriteLine() - overloaded
 Read()
 ReadLine()

You might also like