user2603112
user2603112

Reputation: 85

Calling a void method

Currently I have this code coded as a part of a separate Java class.

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

And I want to call to it from another method. I already have this class instantiated so I can call to it, but I'm not sure how to call to this method since it's a void method.

Upvotes: 6

Views: 69127

Answers (2)

Diego Quirós
Diego Quirós

Reputation: 977

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);    

 }
}

Upvotes: 0

user2277872
user2277872

Reputation: 2973

all you gotta do is

 this.setSubtotal();

since you're doing it inside the same class

Upvotes: 8

Related Questions