Understanding Java Code
Method
A container for our code.
What is a method ?
Contains a set of code that performs some action.
Code
Container
Method is also called as a function.
It is a black box where you can pass some data and get an output.
Method accepts data, performs some manipulation on it and gives us back data.
A method looks like:
Parenthesis(to pass data)
Method Name myMethod(){ Opening Curly Brace(Indicates start of the
method)
//code
Closing Curly Brace(Indicates end of the
method)
Return Type
Every method should have a
return type.
What is a return type ?
int myMethod(){ void myMethod(){
//code //code
} }
Access Modifier
What is an access modifier ?
Something that can modify access of a method.
A method can be accessed inside our outside of a class depending upon its access
modifier.