class is public should be declared in a file named,

0
37
class

What is a “public” class?

In order to understand what this means, it’s important to first know the difference between private and public classes. Public classes are those that are visible from any other part of your program. Private classes on the other hand can only be accessed from within the enclosing class where they were declared. We’ll now look at an example for clarification: class MyClass { //This is a public class because it can be seen outside of its file } The above is an example of a public class. The code below, on the other hand, is not: class MyClass { //This would be considered private because it can only be seen from within its file } In order for you to make your classes public or private in Java, simply use ‘public’ (or ‘private’) at the top of your declaration statement. For example:       class Foo {} becomes either  public static void main(String[] args) {             Foo f = new Foo();         } OR public class Foo {} . Remember that all functions and variables declared after this point are then inaccessible by any other part of your program unless they’re explicitly made available through some

LEAVE A REPLY

Please enter your comment!
Please enter your name here