Variables declared using "public" can be accessed everywhere, except for subclass in other packages.
Variables declared using "public" can be accessed everywhere irrespective of whether it is same package or a different package.
Which of the below members are accessible by the reference variable when the class is instantiated in a different package?
Private members are not accessible outside the class and protected and default members are accessible only within the same package that of the class.
Instance of a subclass which is defined in a different package can access below parent's attributes from within the parent class's package.
Please select 2 correct answers
Protected members are accessible via its instance only within the same package where it is defined. Since we are trying to access the members of Parent class from the same package that of Parent, protected members are accessible though the instance is of different package's class. Default members are completely not visible to other package in all forms.
A top-level class can be defined using below access modifiers:
Please select 2 correct answers
A top-level class can be defined using either public or with no modifier, however, a nested class can be defined using all the access modifiers.
Variables declared without any access modifier are by default private variables.
Variables declared without any access modifier are default variables, it is additional access level in Java, apart from public, private and protected.