Q. Can Protected member of a class invoked in nonsubclss & in different
java file?
if NO then try following programs
A.java
==========================================
// class containing protected constructor...
class A
{
public int i ;
protected A()
{
i=123;
}
protected A(int j)
{
i=j;
}
public static void main(
String [ ]args)
{
System.out.println("Class A!");
}
}
======================================
B.java
================================
// Class where Class A ( having protected Constructor ) get instantiated.....
// Class where Class A ( having protected Constructor ) get instantiated.....
class B
{
public static void main(String[] args)
{
A a1=new A();
A a2=new A(6);
System.out.println("Derived Class B \n a1.i="+a1.i+"\n a2.i="+a2.i+".......");
}
}
---------------
Conclusion : Protected Constructor gets invoked in nonsubclss.
Why it happens?