Credits

Saturday, February 28, 2009

Methods as Functions of Java

Like C or C++, modular programming is also enforced in Java. We employ this through methods.

A method must be defined inside a class but this can be called from other classes.
Try the sample class below.



[+/-] show/hide



public class samplemethods1{
public static void main(String [] args){

System.out.print("hello\n");
init(); /*invoking the method*/
}

public static void init() /*this is the method*/
{
System.out.print("hi\n");
}}

AddThis