In C# or Java, how can I make a class that can only be instantiate with the Interfaces it implemented on?
Sorry if this question is asked before.
Edit: Sorry for confusing you, and this question is just asked out of curious:
For example I have:
interface iA
{
int addNum();
}
interface iB
{
int minusNum();
}
class A implements iA, iB
{
private int A;
public int addNum()
{
A += 10;
return A;
}
public int minusNum()
{
A -= 10;
return A;
}
}
class TestIface
{
public static void main(String args[]) {
A testA = new A();
iA testiA = new A();
iB testiB = new A();
testA.minusNum(); // No error, it has access to both methods
testA.addNum();
testiA.minusNum();//ERROR
testiA.addNum();
testiB.minusNum();
testiB.addNum();//ERROR
}
}
I wonder if there is a way to prevent dev from just make testA and access both methods.