Modifier Types
- All the variables of interface should be ?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
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.
- What is true of final class?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Final class cannot be inherited. This helps when we do not want classes to provide extension to these classes.
- How many copies of static and class variables are created when 10 objects are created of a class?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Only one copy of static variables is created when a class is loaded. Each object instantiated has its own copy of instance variables.
- Can a class be declared with protected modifier?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Protected class member (method or variable) is like package-private (default visibility), except that it also can be accessed from subclasses. Since there is no such concept as ‘subpackage’ or ‘package-inheritance’ in Java, declaring class protected or package-private would be the same thing.
- Which is the modifier when there is none mentioned explicitly?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Default is the access modifier when none is defined explicitly. It means the member (method or variable) can be accessed within the same package.