Class myclass()
{
     int a=10;
     static int b=20;
}
Class test()
{
     myclass A=new myclass();
     A.a=10;           //正确
     A.b=20;           //不能通过对象访问类中的静态成员
     myclass.a=10;  //不能通过类访问非静态成员
     myclass.b=20;  //正确
}

通过这个简单的事例,我们就可以很清楚的了解类中的静态成员与非静态成员的区别。

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-04-03
  • 2022-12-23
  • 2021-10-05
  • 2021-09-14
  • 2022-12-23
猜你喜欢
  • 2021-10-23
  • 2021-10-07
  • 2021-05-24
  • 2022-12-23
相关资源
相似解决方案