In any Java Class the first part is the declaration part. Which is used to declare the objects.
It does not contain any code for any specified Operations, Like
Assigning a value to a variable, do a mathematical operations etc.
here you are initializing the array arr1
arr1 = new int[10];
outside a function. If you really want to do an initialization you can do it Like this
int arr1 = new int[10];
which initialise the array at the time of creation. Else, you can initialise it inside any method.It need not wants to be a main function.
Its because, a function is a set of codes that needs to be executed
and a class is a group of objects and associated functions.
public class Array {
int arr1[];
public String anyFunction(){
arr1 = new int[10];
}
}
Look Here formare details about class.