CJCoding With Joseph
← Back to Question List
C# Code Walkthrough #47

Static Field Shared Across Instances

hardClasses

📄 Code

Read carefully — what does this print?
1new Widget();
2new Widget();
3new Widget();
4Console.WriteLine(Widget.Total);
5 
6class Widget
7{
8 public static int Total = 0;
9 public Widget() => Total++;
10}

🎯 Your Answer