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);
}
}
- Question 1: how I am able to get the static class field (class variables /instance variables) from the non-static method of other class by creating an object of a static field that is residing. I know that only non-static content will be in the object then how I am able to get that value?
- Question 2: How I am able to create a method with the same name as the class? (I think it is not a constructor as void is added to it)
- Question 3: while printing the output is "ZERO" the default constructor is created by JVM as I am not coded any. My question is do the default constructor initializes the class variables to "ZERO"?