Modifier Types
- Which one of the following is not an access modifier?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Public, private, protected and default are the access modifiers.
- All the variables of class should be ideally declared as ?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The variables should be private and should be accessed with get and set methods.
- What is the output of this program?
class box_area
{
int w;
int l;
int h;
box_area()
{
w = 7;
l = 4;
h = 2;
}
void volume()
{
int vol = w * h * l;
System.out.println(vol);
}
}
public class cons_method
{
public static void main(String args[])
{
box_area obj = new box_area();
obj.volume();
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Output: 56
- How can a protected modifier be accessed?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The protected access modifier is accessible within package and outside the package but only through inheritance. The protected access modifier can be used with data member, method and constructor. It cannot be applied on the class.
- What happens if constructor of class N is made private?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
If we make any class constructor private, we cannot create the instance of that class from outside the class.