[Solved] Access modifiers in java | SoloLearn: Learn to code for FREE!

0

[Solved] Access modifiers in java

Whenever I try to declare a variable as private it shows 'illegal start of expression' error. Why does that happen?

7/5/2020 6:30:50 PM

SHIVANSH

14 Answers

New Answer

+3

SHIVANSH We cannot declare local variable as a private. Variable defined in method is called as local variable.

+3

I guess because of syntax error. But we need your code to be sure.

+2

SHIVANSH Because variable declared inside a method is bydefault private. We cannot access that variable outside the method. So there is no need to declare variable as private. That's why it gives syntax error.

+1

SHIVANSH Can you show your Code?

+1

AJ Anant - C#/Java Challenger Denise Roßberg https://code.sololearn.com/cJ28R3hUZ5xR/?ref=app

+1

AJ Anant - C#/Java Challenger Thanks

+1

SHIVANSH No need to delete. It will be helpful for others who face this type of problem.

+1

SHIVANSH Even you can add [Solved] in starting of the question.

+1

Private variables are not global variable and are used in the same function ,if used so outside the particular function in which it is declared, it will give error.

+1

Ok brother.

0

AJ Anant - C#/Java Challenger Thanks🙂 But why is that so?

0

AJ Anant - C#/Java Challenger Thanks again🤗 A question.. Am i supposed to delete this discussion after i have got my answer?

0

AJ Anant - C#/Java Challenger Ok

0

shubham kumar Thanks 🙂