A class will contain one or more methods. Each method is surrounded in {} to seperate them. Mehods are covered in detail in the next section.

public class person{
    String name;
    int age;
    {
        System.out.println("Starting up class");
    }
    public Person(String name, int age){
        this.name = name; this.age = age;
    }

    public void output(){
        System.out.println("Name =" + name + " age = " + age);
    }

}

The above code has two methods. They have been coloured differently to help to seperate them. Notice that he methods have their definitions followed by {} surrounding the code of the method. Each method is seperate and the code within can only be run if the method is called.

next selection and itteration blocks >>

 
Basics
Menu
Search