package p1;
class C1
{
protected void printing()
{
System.out.println("Sai");
}
}
package p2;
import p1.*;
class c2 extends c3
{
public static void main(String[] args)
{
C1 c1inst=new C1()
//Here i want to call the protected method
//The following line will certainly throw error protected property cannot //non-subclassbe accessed in a nonsubclass in other package
c1inst.printing();
}
}
package p2;
import p1.*;
class c2 extends c3
{
public static void main(String[] args)
{
C1 c1inst=new C1()
//Here i want to call the protected method
//The following line will certainly throw error protected property cannot //non-subclassbe accessed in a nonsubclass in other package
c1inst.printing();
}
}
package p2;
import java.lang.reflect.*;
import p1.*;
class c2 extends c3
{
public static void main(String[] args)
{
C1 c1inst=new C1()
Method m = c1inst.getClass().getDeclaredMethod("printing", null);
m.setAccessible(true);
m.invoke(t, null);
}
}
Sai
cmbhatt
Originally posted by Chandra Bhatt:
Using Reflexion is just violation of Object Oriented Programming
Originally posted by Ove Lindstr�m:
*Evil laugh*
Funny thing, I actually found I had to use that exact technique last week.Originally posted by Ove Lindstr�m:
Also, if I would find out that someone was doing that, I would crank the security on my protected class so that reflection is not allowed and then your application would be broken. *Evil laugh*
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|