It is disadvantageous to use public variables in classes because . . . . . . . .

Its values cannot be initialized
It results in compilation error
It cannot be accessed by other variables
It cannot control its values

The correct answer is: D. It cannot control its values.

Public variables are variables that are accessible from outside the class. This means that any other class can access and modify the value of a public variable. This can be a security risk, as it means that other classes could potentially modify the value of the variable in an unexpected way. Additionally, it can make it difficult to maintain the code, as it can be difficult to keep track of all the different places where a public variable is being accessed and modified.

The other options are incorrect.

  • Option A is incorrect, as public variables can be initialized just like any other variable.
  • Option B is incorrect, as public variables do not result in compilation errors.
  • Option C is incorrect, as public variables can be accessed by other variables.
Exit mobile version