Keywords:
Static :
static keyword refers to class specific information.
Static keyword have only one memory copy.
In the static keyword class can common for all object.
Non-static:
Non-Static Keyword refers to object specific information.
Non static have multiple memory copy.
In the non static keyword object have the specific information.
Return Type:
The return statement is used to exit from a method and optionally pass a value back to the code that called the method.
Return statement is the last statement in the method definition.
If the method has a return type (like int, String, boolean, etc.), return sends a value of that type back.
If the method is declared as void, return; simply ends the method early (and doesn’t return any value).
Example:
String buy() { System.out.println("buy method"); return "thank you" }
Method:
A method in Java is a block of code that performs a specific task. It is used to define behavior or functionality that can be reused.
Example:
String buy() { System.out.println("buy method"); }
Object:
In Java, an object is an instance of a class. It represents a real-world entity with state (data) and behavior (methods).
## Key concepts:
- Class: A blueprint or template.
- Object: A real thing created from the blueprint.
syntax for object:
Home Person = new Home();
Home - Home is the name of the class.
Person - Person is the name of the variable.
new Home - new Home is the keyword used to create new object from the class.
Void:
This method does not return anything.
It is used when a method performs an action, but doesn’t give back a result.
Variables:
Local Variables:
Local variable declared in side the function or block.
Global variables:
Global variable declared outside the function.
Top comments (0)