Call the void method

This code is currently encoded as part of a separate Java class.

public void setSubtotal () { subtotal = Validator.getDouble(sc,"Enter subtotal:", 0, 10000); } 

And I want to call him using a different method. I already have an instance of the class, so I can call it, but I'm not sure how to call this method, since it is a void method.

+4
source share
2 answers

all you have to do is

  this.setSubtotal(); 

since you do it inside the same class

+5
source
 public class Y{ public static void main(String args[]){ X foo = new X(); foo.setSubtotal(); } } public class X{ public void setSubtotal () { subtotal = Validator.getDouble(sc,"Enter subtotal:", 0, 10000); } } 
0
source

Source: https://habr.com/ru/post/1492522/


All Articles