title: Scala get local variable from another class
body: <p>Good morning I have a class called Application, it has a def that cannot change and returns an int, inside it I have defined a path that is a local variable, from another class called App that extends to the Application class, how can I get that variable local? I have tried to assign with a variable outside the block but its value is null. Thank you very much for helping me.</p>
  <p>...</p>
  <pre><code>class App extends Application {
      println(&quot;Inside of APP&quot;)  
      println(mypath)  
  }
  
  class Application {
      var mypath: String = _
      def functionname() : Int = { 
          var exitCode = 0
  
          val localPath: String = &quot;C:/path&quot;
          mypath = localPath
          println(localPath)
  
          exitCode
      }
      println(mypath)
  }
  
  object HelloWorld {
      def main(args: Array[String]): Unit = {
          val origin = new Application() 
          println(origin.functionname)
      }
  }
  </code></pre>
  <p>The Output is:</p>
  <pre><code>null  --&gt;  //This is value of myPath outside block (KO)
  C:/path  -&gt;  //This is value of Local Variable (OK)
  0 --&gt; is OK
  the println of the App class is not show (KO)
  </code></pre>
  <p>I have edited the code to explain it better, you can only make the instance of val origin = new Application(), since the program allows you to do one, now what I don't know how to do is that the App class can get the local value of the class Application, but I don't get value and it doesn't show println(&quot;Inside of APP&quot;)</p>
  <pre><code>    class App extends Application {
      println(&quot;Inside of APP&quot;)
      val app = new App()
      app.functionname()
      println(app.mypath)
  
      }
  
     class Application {
       var mypath: String = _
  
       def functionname(): Int = {
         val exitCode = 0
         val localPath: String = &quot;C:/path&quot;
         mypath = localPath
         println(mypath)
         exitCode
        }
  
        println(mypath)
        }
  
  
       object HelloWorld {
          def main(args: Array[String]): Unit = {
             val origin = new Application()
             println(origin.functionname())
             println(&quot;===========&quot;)
             println(origin.mypath)
  
  
  
               }
             }
  </code></pre>
  <p>...</p>