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

Java编程思想组合语法

Java编程思想组合语法

道可道非常道 2016-09-28 19:59:42
package TestPackage;class WaterSource {private String s;WaterSource() {System.out.println("WaterSource()");s = "Constructed";}public String toString() {return s;}public class SprinklerSystem {private String value1,value2,value3,value4;private WaterSource source = new WaterSource();private int i ;private float f;public String toString() {return"value1 = " + value1 + " " + "value2 = " + value2 + " " + "value3 = " + value3 + " " +"value4 = " + value4 + "\n" + "i = " + i + " " + "f = " + f + " " +"Source = " + source;}}public static void main(String[] args) {SprinklerSystem sprinklers = new SprinklerSystem();System.out.println(sprinklers);}}main方法第一句SprinklerSystem sprinklers = new SprinklerSystem(); eclipse报出的错是No enclosing instance of type WaterSource is accessible. Must qualify the allocation with an enclosing instance of type WaterSource (e.g. x.new A() where x is an instance of WaterSource).请问这是为什么?
查看完整描述

2 回答

?
我是偶哦

TA贡献10条经验 获得超3个赞

public class SprinklerSystem { --> public static class SprinklerSystem {   这是内部类的语法,内部静态类不需要有指向外部类的引用。但非静态内部类需要持有对外部类的引用。

查看完整回答
1 反对 回复 2016-09-28
  • 2 回答
  • 4 关注
  • 1562 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信