User-Defined Methods Flashcards
What is a program?
It is a set of instructions given to the computer to solve a particular problem
How are instructions in a program specified,
In forms of methods in Java
What are methods known as in other programming languages?
functions, procedures, modules, subroutines or sub-programs
Where do the methods exist?
Inside a class
Name the two types of methods
- System defined methods
2. User Defined Methods
What are system defined methods??
The methods defined by the developers of Java
Give other names for system defined methods
Library methods or built in methods
What are user-defined methods?
The methods defined by the user. They are defined as per the need of the user to create customised and reusable blocks of code
Give the advantages of methods
- They provide the means to avoid duplication of the code and help in code reusability
- They help divide complex programs into manageable code blocks
- They help in understanding the flow of a program
- They help in improving the readability of the code
- They make debugging of the code easier
When are the methods defined inside the class?
Immediately after the member variables
Give the syntax of a method definition
[access modifier] type method-name ([parameter list])
{
method body;
}
What is the first line of the method definition called?
Method prototype or method header
Name the five main parts a method definition can be divided into
- The method prototype - begin w/ a.m.
- Data returned if any valid java d.t
- Method name can be any identifier
- Parameter list -sequence of d.t and identifier pairs
- Statements must be within method body
What may the method prototype begin with?
An access modifier
What are the forms the access modifier can take?
Public, private or protected
What do access modifiers determine?
The type of access to the method
Why are access modifiers or specifies called so?
They specify if elements outside the class can use this method
What do square brackets around access modifiers indicate?
This part of the method definition is optional
What is the type when the method doesn’t return a value?
Void
Give other names for the parameter list
Parameters or arguments
What happens if a method has no parameters?
Its parameter list will be empty, but you must use empty round brackets. Parameters are optional
What is the method signature?
The method name along with the list of parameters used in the method prototype
In ‘public void HelloMessage’, give the meaning of each term?
public - modifier
void - return method
HelloMessage - method name
() - no parameters inside
When can no values be passed onto a method?
When its parameter list is empty
What does the parameter provide a mechanism for?
Passing information to the method
How can a method be invoked?
By specifying its name, followed by parameters being sent enclosed in the round brackets