为了账号安全,请及时绑定邮箱和手机立即绑定

从静态方法返回一个类对象

从静态方法返回一个类对象

梦里花落0921 2021-05-31 17:47:48
我正在使用 static 关键字。我已经声明了一个返回类型为类的静态方法。当我从 main 方法访问此方法时,出现以下错误。如何从此方法返回对象?error: non-static variable this cannot be referenced from a static context            return this;以下是我的代码public class StaticKeyword{   public static StaticKeyword run(){     return this;   }   public static void main(String args[]){     System.out.println(StaticKeyword.run());   }    }
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 342 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号