Skip to content
Sign upLog in
← Back to Community

whats the difference between public static void and private static void in java

Profile icon
MatthewXia

i have no idea........................................................................................really...................................................................................idk why.................................................................................but i actully dont know.....................................................i shud tho....................................................why.................................................................and..........................................................wut..........................................................am..........................................................i..........................................................doing..........................................................with..........................................................my..........................................................life?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
MatthewXia
Comments
hotnewtop
Profile icon
Coder100

So like, if a person was a class:

class Person { public name() {} private creditCard() {} } Person me = new Person();

Others should be able to call me.name() to get my name, but shouldn't be able to call me.creditCard() because only I can access that, nothing else can.

Profile icon
Coder100
class Something { public a() { } private b() { } } Something c = new Something(); c.a(); // public so you can call it c.b(); // ERROR is private so you can't