package com.vamsi.java;
public class Class1 {
int myNumber = 799;
}
public class Class1 {
int myNumber = 799;
}
package com.vamsi.java;
public class Practice {
public static void main(String args[]) {
Class1 obj = new Class1();
System.out.println("Hai vamsi"+obj.myNumber);
}
}
these two classes are in same package.
package com.vamsi.package2;
import com.vamsi.java.Class1;
public class Class2 {
public static void main(String args[]) {
Class1 obj = new Class1();
System.out.println("Hai vamsi"+obj.myNumber);
}
}
class2 is some other package.
so, the variable scope only with in the package. out of the scope it will not accessible. it is accessible when it is in public.
No comments:
Post a Comment