What is the difference between "public class"&"class" java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between "public class"&"class" java?

6th Feb 2023, 7:04 AM
Munkhtamir Enkhtuya
Munkhtamir Enkhtuya - avatar
1 Answer
+ 8
public is accessible for all parts of your program and also for other (external) programs. When you have only "class" without the public keyword, it is also known as "package-private", that is only accessible for code that is located in the same package. To understand this, you should also be aware of namespaces: how a Java program is organized in folders that represent a package hierarchy, and how each Java file is connected to the others in the same package or other packages, by the "import" mechanism.
6th Feb 2023, 8:40 AM
Tibor Santa
Tibor Santa - avatar