-6

I am working on a TicTacToe game and have to create several methods to handle various parts of the game. One of the methods is to clear the board for a new game. This is what I have for the method:

void resetBoard() 
{
    button_square_one = " ";
    button_square_two = " ";
    button_square_three = " ";
    button_square_four = " ";
    button_square_five = " ";
    button_square_six = " ";
    button_square_seven = " ";
    button_square_eight = " ";
    button_square_nine = " ";
}

In the onCreate() method: 

    // Assign button objects to ids
    Button button_square_one = (Button)findViewById(R.id.r1c1_button);
    Button button_square_two = (Button)findViewById(R.id.r1c2_button);
    Button button_square_three = (Button)findViewById(R.id.r1c3_button);
    Button button_square_four = (Button)findViewById(R.id.r2c1_button);
    Button button_square_five = (Button)findViewById(R.id.r2c2_button);
    Button button_square_six = (Button)findViewById(R.id.r2c3_button);
    Button button_square_seven = (Button)findViewById(R.id.r3c1_button);
    Button button_square_eight = (Button)findViewById(R.id.r3c2_button);
    Button button_square_nine = (Button)findViewById(R.id.r3c3_button);

I have created the button objects in the xml file. I was going to create the methods with a return type of void instead of public void.

JimT
  • 99
  • 3
  • 3
  • 11
  • `public` has nothing to do with return types but `method access`. You should do some reading on [method access modifiers](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html) – indivisible Apr 28 '14 at 00:17

3 Answers3

2

With public void the word "public" is not a return type. The public is an access modifier in Java.

The following table shows the access to members permitted by each modifier; there are four

public
(none / blank) "package" level
protected
private

Access Levels

|Modifier   |Class|Package|Subclass|World|
------------------------------------------
|public     | Y   | Y     | Y   | Y      |
------------------------------------------
|protected  | Y   | Y     | Y   | N      |
------------------------------------------
|no modifier| Y   | Y     | N   | N      |
------------------------------------------
|private    | Y   | N     | N   | N      |
------------------------------------------
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
1

This has already been answered here: In Java, difference between default, public, protected, and private

Without specification of an access modifier the access is determined by the classes location within the package hierarchy. Similar to public, but not the same by any means.

Community
  • 1
  • 1
0

public is a visibility modifier, in this case there would be no limitation on which classes can access the method

void is a return type, void means the method doesn't return anything to the caller.

yitzih
  • 3,018
  • 3
  • 27
  • 44