Reputation: 117
For info, I am using java 8.
public class You {
static int x;
public static void main(String args[]){
Iam c= new Iam();
c.Iam();
}
}
class Iam{
public void Iam(){
You c =new You();
System.out.println(c.x);
}
}
Upvotes: 2
Views: 171
Reputation: 274
Please go through basic java documentation on class variables
Method with same name is called constructor of the class, please go through java documentation, java would still allow you to define a method with the same name as ctor with a return type.
Your static variable is primitive, which are always initialized with default values for 'int' its zero
Good starting for learning Java is at Learning the Java Language
Upvotes: 1