When we should make an instance variable private - Java

Explain when should we make an instance variable private.

- The variables which are defined within the class are known as instance variables.
- Each instance of this class contains its own copy of these variables.
- These variables can be declared as public,private or default.
- This variable can be declared as private to promote information hiding so that no other object can access them.
Overridden methods in Java
Overridden methods of super class in subclass allow a class to inherit and behave close enough...
Is C++ access specifier called protected is similar to Java’s?
The java access specifier ‘protected’ is placed proceeding the member of the class and the access control is applicable only for that particular definition...
Why should we catch super class exceptions?
Every exception is represented by the instance of Throwable or its subclasses. An object can carry the information for the exception raising point to the exception handler which catches it...
Post your comment