25
1
using System;
2
public class Sample {
3
public static int a=10,b=15;
4
private Sample()
5
{
6
}
7
8
public static int sum()
9
{
10
return a + b;
11
}
12
}
13
14
public class PrivateConstructorProgram {
15
public static void Main(string[] args)
16
{
17
// calling the private constructor using class name directly
18
int result = Sample.sum();
19
Console.WriteLine(result);
20
21
// Below code will throw the error as we can't create object of this class
22
// Sample objClass = new Sample();
23
}
24
}
25
Cached Result