Hi folks,
List of doubts on Access Modifiers
1.Are there no protected classes?? Y not if “protected” signifies that it can be accessed/extended by the sub-classes.
2.Please give me a real example of static classes.
3.Is it possible to equate static methods with final methods??
4.Is it possible to sub-class a private class, when it is not even accessible?
5.Is void a datatype?
6.Consider the following eg:
public class SuperClassA{
protected int superClassVarA;
protected void superClassMethodA(){
System.out.println("In superClassMethodA method");
}
}
public class SubClassB extends SuperClassA{
SuperClassA objRefA = new SubClassB(); //1
SubClassB objRefB = new SubClassB(); //2
void subClassMethodB(){
objRefB.superClassMethodA(); //3
objRefA.superClassVarA; // 4
}
}
Here an object of the SuperClassA(objRefA) is referencing the object of the subclassB. Since the member variable “superClassVarA” is protected in the Superclass A, y is it not available to the SubclassB?
7. When a particular native method returns a class reference then how does
java handle such a return value, when it does not even know the definition of hte class(the member variables and its methods)