User-Defined Methods Flashcards

1
Q

What is a program?

A

It is a set of instructions given to the computer to solve a particular problem

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

How are instructions in a program specified,

A

In forms of methods in Java

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

What are methods known as in other programming languages?

A

functions, procedures, modules, subroutines or sub-programs

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

Where do the methods exist?

A

Inside a class

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

Name the two types of methods

A
  1. System defined methods

2. User Defined Methods

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

What are system defined methods??

A

The methods defined by the developers of Java

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

Give other names for system defined methods

A

Library methods or built in methods

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

What are user-defined methods?

A

The methods defined by the user. They are defined as per the need of the user to create customised and reusable blocks of code

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

Give the advantages of methods

A
  1. They provide the means to avoid duplication of the code and help in code reusability
  2. They help divide complex programs into manageable code blocks
  3. They help in understanding the flow of a program
  4. They help in improving the readability of the code
  5. They make debugging of the code easier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When are the methods defined inside the class?

A

Immediately after the member variables

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

Give the syntax of a method definition

A

[access modifier] type method-name ([parameter list])

{
method body;
}

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

What is the first line of the method definition called?

A

Method prototype or method header

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

Name the five main parts a method definition can be divided into

A
  1. The method prototype - begin w/ a.m.
  2. Data returned if any valid java d.t
  3. Method name can be any identifier
  4. Parameter list -sequence of d.t and identifier pairs
  5. Statements must be within method body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What may the method prototype begin with?

A

An access modifier

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

What are the forms the access modifier can take?

A

Public, private or protected

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

What do access modifiers determine?

A

The type of access to the method

17
Q

Why are access modifiers or specifies called so?

A

They specify if elements outside the class can use this method

18
Q

What do square brackets around access modifiers indicate?

A

This part of the method definition is optional

19
Q

What is the type when the method doesn’t return a value?

A

Void

20
Q

Give other names for the parameter list

A

Parameters or arguments

21
Q

What happens if a method has no parameters?

A

Its parameter list will be empty, but you must use empty round brackets. Parameters are optional

22
Q

What is the method signature?

A

The method name along with the list of parameters used in the method prototype

23
Q

In ‘public void HelloMessage’, give the meaning of each term?

A

public - modifier
void - return method
HelloMessage - method name
() - no parameters inside

24
Q

When can no values be passed onto a method?

A

When its parameter list is empty

25
Q

What does the parameter provide a mechanism for?

A

Passing information to the method

26
Q

How can a method be invoked?

A

By specifying its name, followed by parameters being sent enclosed in the round brackets