Java Class Methods

By convention, method names start with a lowercase letter.

[public/private/protected] [static/final/abstract/synchronized] returnType methodName([parameters]) {
    // Method function
}

Access Control Modifiers

  • public

    • public can be accessed and called from all classes.
  • private

    • private can be accessed and called only inside the class.
  • protected

    • protected can be accessed and called only from the same package or a subclass.
  • No access modifier

    • A method declared without an access modifier can be accessed and called only from classes in the same package.

static Methods

When static is declared on a method, it means a class method. Since it is allocated in memory only once while the program starts, it is used as a global method. It is used by calling the method directly from the class without separately creating an object.

final Methods

A method with final is a method that cannot be inherited. It means preventing the current method from being inherited by another subclass. This is useful for protecting information.

The concept of inheritance will be explained again in more detail in another chapter.

abstract Methods

A method with abstract is called an abstract method. It is used to specify in advance a method that has only a declaration part in a parent class and no implementation part. If even one abstract method exists, the class must be an abstract class.

The concept of abstract classes will be explained again in more detail in another chapter.

synchronized

A method for thread synchronization.

Return Data Type

This means the type of value returned after the method is executed.

Parameter Variables

A parameter variable is a variable that passes a value to a method.

Local Variables

  • A local variable is a variable declared inside a method. It can be used only in that method.
  • It is created in memory when the method executes and is automatically deleted when the method ends.
  • It can be called anywhere inside the method, but it must be declared before use.

Method Overloading