Tom Lenc
Tom Lenc

Reputation: 765

Jump to other void

I got this code:

public void main(){

}

public void first(){
    System.out.println("first void");
}

public void second(){
    System.out.println("second void");
}

public void third(){
    System.out.println("third void");
}

Now I want to add a code to the main void that would skip to the third one for example. That means, that the console output will be:

third void

Upvotes: 2

Views: 182

Answers (2)

Peanut
Peanut

Reputation: 3973

The following code will produce the desired output:

public void main(){
  third();
}

public void first(){
    System.out.println("first void");
}

public void second(){
    System.out.println("second void");
}

public void third(){
    System.out.println("third void");
}

Please note that it does not "skip" the first and second function, but simply does not call them. I'm not sure whether this makes a difference for you or not.

Upvotes: 5

Jordi Castilla
Jordi Castilla

Reputation: 27003

If you execute your code from your main method call it like

public void main(){
    third();
}

Upvotes: 3

Related Questions