BHUPATHY A P BHUPATHY A P - 1 year ago 56
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(;
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 Source

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



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download