Java Methods

All tutorials are implemented in text (here), and also with exercises and multimedia in the Tutorial Player. The main home page has a search engines, and more facilities.

Overloading
Constructors
Overriding
this
Finalize
Arguments
Public
Static
Void

Overloading

Methods can be overloaded as in other languages. This means that the same method name can be used in a class with a different argument type, and the correct method is automatically executed.

Constructors

Constructor methods do not return a value, they are executed when an object is created (ie when the new method is used).

Overriding

If you implement a method in a sub class, and it also appears in a superclass, then the method is overridden. Java supports this. You can use super to refer to a superclass method.

super.getName();

this

this refers to the current object.

this.getName();

Finalize

Finalize methods are clean up methods used when at object is deleted.

Arguments

Objects are passed by reference and not value. Primitive types are passed by value. This means that primitive types are effectively copied, and changes in the method are local only, but objects are actually changed if they are changed in the method.

public

The word public means that a method can be used by other classes and objects.

public static void main()(String arguments[]) {

}

static

static declares a class method.

public static void main()(String arguments[]) {

}

void

void indicates that no value is returned by a method.

public static void main()(String arguments[]) {

}