Test Preparation on JAVA-Test Prep. Classes and Methods-2
1.
Which of the following modifier means a particular variable cannot be accessed within the package?
Explanation: Private variables are accessible only within the class.
2.
How can a protected modifier be accessed?
3.
What happens if constructor of class A is made private?
4.
All the variables of interface should be?
Explanation: Variables of an interface are public, static and final by default because the interfaces cannot be instantiated, final ensures the value assigned cannot be changed with the implementing class and public for it to be accessible by all the implementing classes.
5.
What is true of final class?
Explanation: Final class cannot be inherited. This helps when we do not want classes to provide extension to these classes.