Java Methods Flashcards
What is a method in Java?
A method is a block of code which only runs when it is called.
Where are methods created in java?
Methods are typically created inside classes or in interfaces. A method in an interface doesn’t not include a code block.
What is the static modifier for a Java Methods?
Static means the method belongs to the class and not to an object that is created
What is the void modifier in Java?
It means the method does not return a value
What are parameters in methods in Java?
Information can be passed to methods as parameter. Parameters act as variables inside the method.
What is required for a parameter?
Need to have the data type and the variable name
Describe a Method in Java
public class MyClass { static void myMethod() { // code to be executed } }
Describe a method with a parameter
public class MyClass { static void myMethod(String fname, int age) { System.out.println(fname + " is " + age); }
public static void main(String[] args) { myMethod("Liam", 5); myMethod("Jenny", 8); myMethod("Anja", 31); } }
// Liam is 5 // Jenny is 8 // Anja is 31
What is method overloading?
Method overloading is the process of using the same method with using a different number of parameters to designate which version of the method is used.
What is the main method?
The main method is the method the compiler looks for when it runs a Java program.
What are java string methods?
In the string class there are several built in methods that enable the modification and manipulation of string.
What are Java Math Methods?
There are built in method in the java class that can be used for Math functions
What are access modifiers in methods in java?
There restrict what has access to the methods in Java or define the process in giving access to these methods.
What the the access modifiers in java methods?
1- Private
2- Default
3- Public
4 - Private
What are non-access modifiers in Java?
Java provides a number of non-access modifiers to achieve many other functionalities.
The static modifier for creating class methods and variables.
The final modifier for finalizing the implementations of classes, methods, and variables.
The abstract modifier for creating abstract classes and methods.
The synchronized and volatile modifiers, which are used for threads.