- 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?

5th Jul 2020, 6:30 PM
SHIVANSH
SHIVANSH - avatar
14 Réponses
+ 3
SHIVANSH We cannot declare local variable as a private. Variable defined in method is called as local variable.
6th Jul 2020, 6:39 AM
A͢J
A͢J - avatar
+ 3
I guess because of syntax error. But we need your code to be sure.
5th Jul 2020, 8:33 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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.
6th Jul 2020, 6:46 AM
A͢J
A͢J - avatar
+ 1
SHIVANSH Can you show your Code?
5th Jul 2020, 7:00 PM
A͢J
A͢J - avatar
6th Jul 2020, 6:40 AM
SHIVANSH
SHIVANSH - avatar
+ 1
SHIVANSH No need to delete. It will be helpful for others who face this type of problem.
6th Jul 2020, 6:49 AM
A͢J
A͢J - avatar
+ 1
SHIVANSH Even you can add [Solved] in starting of the question.
6th Jul 2020, 6:50 AM
A͢J
A͢J - avatar
+ 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.
6th Jul 2020, 4:49 PM
shubham kumar
shubham kumar - avatar
+ 1
Ok brother.
6th Jul 2020, 4:50 PM
shubham kumar
shubham kumar - avatar
0
AJ Anant - C#/Java Challenger Thanks🙂 But why is that so?
6th Jul 2020, 6:37 AM
SHIVANSH
SHIVANSH - avatar
0
AJ Anant - C#/Java Challenger Thanks again🤗 A question.. Am i supposed to delete this discussion after i have got my answer?
6th Jul 2020, 6:48 AM
SHIVANSH
SHIVANSH - avatar
6th Jul 2020, 6:55 AM
SHIVANSH
SHIVANSH - avatar
0
shubham kumar Thanks 🙂
6th Jul 2020, 4:49 PM
SHIVANSH
SHIVANSH - avatar