+ 3

when do we have to use "class" or "public class" ?

2nd Oct 2016, 8:03 PM
Aladin Khénissi
Aladin Khénissi - avatar
3 odpowiedzi
+ 5
class when we want to keep the access restricted to members of same package, public is accessible of other packages.Sorry my basic English.
2nd Oct 2016, 8:20 PM
Wanderlei Borges
Wanderlei Borges - avatar
+ 2
public means you can access the class from anywhere. if there is no class modifier, it is implicitly protected, which means it can be accessed only within the package it is declared. so Class Person is the same as protected Class Person.
2nd Oct 2016, 8:21 PM
Mythos
0
Public class is where public static void main() lives and has to have the same name as your file name. If you are creating objects, then "class" is what you use. This is the simplified version explanation
2nd Oct 2016, 8:17 PM
Flo