U3: User Defined Methods Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Trial and Error

A

Create program, run it, alter code until desired result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stepwise Refinement

A
  • Completing program in trial-and-error method closer and closer to solution
  • Ex: Writing first part of program, perfecting, then continuing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Divide and Conquer

A

Breaks task into smaller parts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modular Programming

A
  • Building large programs through combining separate chunks of code
  • Possible by creating main program, then creating separate subroutines for program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Method Header

A
  • public static void [method] (data)
  • AKA: Subroutine definition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Method Body

A

Code of the method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Modifiers

A

Ex: public and static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

public/private

A
  • Access specifier stating where subroutine can be called from
  • Private: Just within selected part of program
  • Public: Other parts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Naming Conventions for Subroutine

A
  • Begin with lowercase
  • Camel notation
  • Descriptive name
  • No reserved words
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Static

A

Ensures subroutine can exist on own and not as part of object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Local Variables Inside Subroutine

A
  • Different, simpler name from ones in main program
  • Only exist within subroutine
  • Wiped from memory when subroutine done executing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Program Control for Subroutine

A
  • Program control transferred to subroutine when latter is called
  • Transferred to main program when subroutine done executing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Procedure

A

Performs task but doesn’t return data to main program; returns void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Data Transfer from Main Program to Subroutine

A

Write arguments in brackets in same order as parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Function

A
  • Performs task and returns data to main program
  • Return type specified and return statement concludes subroutine
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Return Types

A

Int, Double, String, Void, etc

17
Q

void

A

Used when no data returned to main program

18
Q

Return Statement

A

return (variable);

19
Q

Outputting Data from Method Call

A
  • Output to screen on the same line as the method call OR
  • Use variable in main program to store data
20
Q

Methods

A
  • Declared within main class
  • Include both procedures and functions
  • Can’t return +1 piece of data
21
Q

Declaring Parameter

A

Done while declaring subroutine

22
Q

Declaring Argument

A

Done while calling subroutine

23
Q

Declaring Variables on Same Line

A

Possible for same data type in the main program, not in subroutines

24
Q

Subroutine Header

A

Comments explaining subroutine function, inputs and outputs, parameters passed, data returned (if any).