Method in Java Flashcards

1
Q

what is method ?

A

A method is a block of code that or collections of instructions that perform a specific task, and return the result to the caller, when the method is called

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

name the types of method.

A

The types of method are:
1.predefined method: method that is already defined in the Java class libiaries.

  1. User defined method: the method written by the user or programmer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a parameter?

A

A variable which is part of a method signature.

parameter is a place holder in the definition of a function for a value that will later be passed into a function/method when a function is called.

parameter act as variable in a method

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

what is a Argument?

A

Argument are the actual value given to the method when a method is called.

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

what is pass by value and pass by reference?

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

what is the syntax for a method

A

public static (return type) (method name)(parameter){
// method body
}
Example: public static int getnumber(int num1 , num2){
return num1 + num2;

{

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

why use method?

A
  1. to reuse code
  2. define the code once and use
    it many time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to call a method

A

to call a method in Java, write the method’s name followed by two parentheses() and a semicolon.
Example: myMethod();

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

can a method be called one time?

A

no, a method can be call many time as you want.

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

what are value returning method?

A

A method that return a value .
the return type is the type of the data that will be returned.

Example: public static int getNumber(int num2, num3){
// this method return type is an int.
}

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

what is method overloading?

A

method overloading is writing the same method with different parameter.
1. overloaded method can have different return type.
2. overloaded method must have different parameter.

example: public static void sayHi(){
System.out.println( “hi”);
}

public static String sayHi(){
return “hi”;
}

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

What is the return keyword?

A

A keyword that is used to return a value from a method.

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