Game Development Reference
In-Depth Information
in detail here, just to make sure, as access (security) is an important issue these days,
inside your code as well as in the outside world. I will start with the least amount of ac-
cess control first!
Java's Public Modifier: Allowing Access by the Public to
Java Program Constructs
The Java public access modifier keyword can be used by classes, methods, construct-
ors, data fields (variables and constants), and interfaces. If you declare something pub-
lic, it can be accessed by the public! This means that it can be imported and used by
any other class, in any other package, in the entire world. Essentially, your code can be
used in any software that is created using the Java programming language. As you will
see in the classes that you use from the Java or JavaFX programming platforms (APIs),
the public keyword is most often used in open-source programming Java platforms or
packages that are employed to create custom applications, such as games.
It is important to note that if a public class that you are trying to access and use ex-
ists in a package other than your own (in your case, invincibagel), then the Java pro-
gramming convention is to use the Java import keyword to create an import statement
that allows use of that public class. This is why, by the time you reach the end of this
book, you will have dozens of import statements at the top of your InvinciBagel.java
class, as you will be leveraging preexisting Java and JavaFX classes in code libraries
that have already been coded, tested, refined, and made public, using the public access
control modifier keyword, so that you can create Java 8 games with them to your
heart's content!
Owing to the concept of class inheritance in Java, all the public methods and pub-
lic variables inside a public class will be inherited by the subclasses of that class
(which, once it is subclassed, becomes a superclass). Figure 3-2 offers an example of a
public access control modifier keyword, in front of the InvinciBagel class
keyword.
Java's Protected Modifier: Variables and Methods Allow
Access by Subclass
The Java protected access modifier keyword can be used by data fields (variables and
constants) and by methods, including constructor methods, but cannot be used by
classes or interfaces. The protected keyword allows variables, methods, and construct-
Search WWH ::




Custom Search