Call a class from several

0

I have a class that calls LEEKs.java in that class I read Kh with Kh = Viga.Kh and then in the class (beam) that called LEEKs.java I get the values Ks , Kz , Kx that are " Double " and also Sigma that is " String " with Ks = LEEKs.Ks and get the others with something similar.

The problem is that I want to send Kh from other classes to get the values of Ks , Kz , Kx and Sigma and I can not use Kh = Bases.Kh why values would be superimposed.

In short you would have to call LEEKs (sending Kh ) and get ( Ks , Kz , Kx , Sigma ) back. You may have to use a " Metodo " or something else. thank you very much

    
asked by luisbisson 31.05.2016 в 16:42
source

1 answer

1

I'm not completely sure that I understood what you want, it would be nice if you extended your query with code fragments. As I understand you want to send data from one class to another (in this case Kh) to return a different value depending on the entry). To do that, the two most common solutions are these.

1. Builders

To pass that value to the class you must create a constructor.

String Kh = null;

public LEEKS(String Kh){
     this.Kh = Kh;
}

In this code fragment we pass to the LEEKS class the value of Kh through the definition of the class (that is, instantiating it).

LEEKS leek1 = new LEEKS("aqui va el valor de KS");

Here you have more information about the use and definition of builders:

link

2. Setters

You can use setters to give a value to Kh in the LEEKS class. You must define the setter like this:

We would declare a method in the LEEKS class

public void setKh(String Kh){
      this.Kh = Kh
}

And it would be as easy as calling that method with the desired value

setKh("valor de Kh");
    
answered by 01.06.2016 в 09:46