Why can't static classes have non-static methods and variables?

前端 未结 3 1347
小蘑菇
小蘑菇 2020-12-15 10:10

Why can\'t static classes have non-static methods and variables when non-static classes can have static methods and variables?

What is the advantage of having static

3条回答
  •  眼角桃花
    2020-12-15 10:29

    Static class can't contain non-static members because by definition it can't be instantiated so there's no possibility to use these members.

    However, static members in non-static class can be used without having class instance - a bit different scenario, i.e. for utility methods or factory methods.

提交回复
热议问题