Accessing values of static private variabes from other classes
Hi all,
I've 2 java classes in a package. I want to access the values of the private variables in the first class A from the second class B but the value that I get is null, can anybody help me?
Here is the code:
package Test;
class A{
private static String name;
public static void main(String args[]){
A obj = new A();
obj.setName("Abebe");
System.out.println(obj.getName());
}
public static String getName() {
return name;
}
public static void setName(String aName) {
name = aName;
}
}
//and the second file is
package Test;
public class B {
public static void main(String args[]){
A obj2 = new A();
System.out.println("Name: " + A.getName() ); // this gives me null, why ? , I was expecting "Abebe"
System.out.println("name:"+ obj2.getName()); // this gives me null 2, helppppppp? I was expecting "Abebe"
}
}

