- 1
[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?
14 Answers
+ 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
+ 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
shubham kumar Thanks 🙂