Create public class in C# such that following conditions are satisfied :
- The class cannot be instantiated.
- A function from that class can be called by other class.
I tried this way :
public abstract class A {
public static void fun()
{
// do process.
}
}
public class B : A
{
// Now A can't be instantiated being abstract.
// And you can call its function like this :
A.fun();
}
But my answer was wrong.So, please help me out.
You can create a class like as follows to meet your goal
Making the constructor of A private would bar it from instantiating from another class. And the static method GetA will return an object of A instatiating it privately which you can use from any class.