+ 3

Question about public access modifier for a class in Java.

I just started learning about objects and classes in Java. So I made this simple code for practice. https://code.sololearn.com/cBffP9Q9pd44/?ref=app I'm using "command prompt" for running my programs.(I know I can use better IDE's ,but I really want/like to *learn* using command...) The problem I faced here is that when I start my class definion (of class 'Warrior') like public class Warrior {.... On compilation I get an error message "class warrior is public, should be declared in a file named Warrior.java" So why this error ? This doesn't occur if I try on sololearn . Also private modifier doesn't work...(shouldn't that be by default) It works only when I leave class definitions without any specifiers.like class Warrior{... Please help me understand why this happened on command prompt and not on SL. I'm just getting started and I can't move further without getting clear idea of what I'm currently learning and this is my first code on sl so please give your valuable suggestions. Thank you... 🙏☺

1st Oct 2019, 5:02 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
1 ответ
0
Just run it it should work perfectly
1st Oct 2019, 5:21 PM
max flame
max flame - avatar