BHUPATHY A P BHUPATHY A P - 1 month ago 7
Java Question

what happens while Creating object for class with main method in java

Whats happens when i create object for class with main method.Can i able to use those instance variables within main method,since they are in same class?

class matrix
{

int i,j;
int a[10];
Scanner one=new Scanner(System.in);
public static void main(String args[])
{
matrix obj=new matrix();
System.out.println("Enter the numbers");
obj.create(a); // is it correct to use 'a'(instance variable) inside main() ?
}



void create(int[] a)
{
// code
}

Answer

No, because you cannot use non-static variable in static method, change

obj.create(a)

to

obj.create(obj.a)