java - How to acces local variables in another class -


i making program needs variable main method, when try import using main main = new main(); can't access variable. how can use variable in class?

public class main{     public static void main(string[] args){         int = 10;     }   }  public class someclass{     main mainclass = new main();     main.a;//i errors when } 

that why called "local" variable. available locally in scope defined in , can in no way whatsoever access variable unless add native code , mess dirty pointers.

if need a in class , static main method need make a static member of class, pulling outside local scope like

public class main{     static int a;     public static void main(string[] args){         = 10;     }   }  public class someclass{     main.a; } 

but think should book java , object oriented development before proceed, because example shows have not many clues both of them.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -