class - Clone Method Java -


I am trying to create a clone method that will take the already prepared rational form and create a copy That can do something like this in my head:

  rational = r3 = new rational (r1);   

So far, I made a method in my rational class that would take it as a rational parameter; Although I'm not sure how to show new examples as parameters.

  Public Rational Copy (Reasonal Aerial) {int newNum = aRational.n; int newDenom = aRational.d; Return (new rational (new name, new daemon));   

}

Any help or insight is highly appreciated!

In my main [me] there is something to do: rational r3 = new Rational (r1);

This is not cloning, it is creating a constructor which takes a logical as a parameter. You can do this:

  Public rational (other rational) {n = other.n; D = other.d; }   

This will allow you to use the code to create new examples of rational from the current versions.

Note: It seems that both n and D are displayed in your class as public variables in your class, this is not ideal Because, because there is no control over your modifications, one of the best ways that your class users can do at their frequency variables is to make them personal and add gates and saturs to their class. This approach will allow you to identify attempts to denote zero which can be desirable.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -