Kasun Liyanage wrote:i mean, if one class is already initialized and if i want to access a variable in that class from another class...
If you're
really talking about
classes (that is, static variables), then simply use the class name. For example, MyClass.x or MyClass.y.
But if you're talking about
instances of these classes, then you need a reference to that instance. For example...
Note that in the above example, a constructor ensures that each instance of ClassB HAS-A specific instance of ClassA. Then within that instance of ClassB, you can use myA.x to access the variable. (Assuming there are no access restrictions.)