eclipse提示No enclosing instance of type Constructor is accessible
学习JAVA中构造方法的使用,输入如下程序:
public class Constructor {
public static void main(String[] args)
{
Person p=new Person(12);
p.show("JAVA构造方法演示");
}
class Person
{
public Person(int x)
{
a=x;
System.out.println("构造方法被调用");
System.out.println("a="+a);
}
public void show(String msg)
{
System.out.println(msg);
}
private int a;
}}
运行后在红色字体处系统提示:
No enclosing instance of type Constructor is accessible. Must qualify the allocation with an enclosing instance of type Constructor
(e.g. x.new A() where x is an instance of Constructor).
无访问类型构造的封装实例,必须分配类型构造的封装实例。
因此将程序修改如下:
public class Constructor {
public static void main(String[] args)
{
Constructor pi=new Constructor();
Constructor.Person p=pi.new Person(12);
//Person p=new Person(12);
p.show("JAVA构造方法演示");
}
class Person
{
public Person(int x)
{
a=x;
System.out.println("构造方法被调用");
System.out.println("a="+a);
}
public void show(String msg)
{
System.out.println(msg);
}
private int a;
}}
这一段在书上并未明确,不知这样理解是否正确。
eclipse提示No enclosing instance of type Constructor is accessible相关推荐
- No enclosing instance of type FormDetailBean is accessible. Must qualify the allocation with an encl
最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
java : No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing ...
- [Java]Error:No enclosing instance of type E is accessible. Must qualify the allocation with an enclo
在自己试着写一个链表的例子时,由于参考的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible. Must ...
- No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing i...
最近在刷AC,在编译时出现: No enclosing instance of type Main is accessible. Must qualify the allocation with an ...
- No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing
No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing ...
- Java出现No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosin
最近研究LDA源代码时,里面涉及到Comparable方法的使用.以前用过这个排序方法,现在想回顾一下.以下是程序,感觉没问题啊,结果报错了: Exception in thread "ma ...
- Java变异出现错误:No enclosing instance of type XXX is accessible
摘要:写java代码时遇到下面的编译错误. 本文分享自华为云社区<Java中出现No enclosing instance of type XXX is accessible问题>,作者: ...
- java解决 No enclosing instance of type XXX is accessible的问题
有些时候我们要把Activity的一些实现类移到java类里来实现,比如把写以下两个类: 在LifeCircle这个类中: public class LifeCircle {public class ...
- 异常: No enclosing instance of type xx is accessible. Must qualify (Java 内部类)
异常 前言. 开发时候遇到内部类的问题. 异常 No enclosing instance of type SparkProgrammingGuide is accessible. Must qual ...
最新文章
- Array | 867. Transpose Matrix
- 剑指offer--替换空格
- eclipse黑色主题
- python读取多个文件夹中的音频文件_Python3.7 读取音频根据文件名生成脚本的代码...
- 用c.vim插件打造C/C++集成编辑器
- Macos 12 打不开微信解决方案
- OpenCV精进之路(三):图像处理——形态学滤波(膨胀、腐蚀、开闭运算)
- C程序设计案例(矩形法求定积分问题)
- 被互联网婚恋榨干的你,还会相信爱情吗?
- 跳出舒适区发现更大的世界,来社科院杜兰金融管理硕士项目汲取能量挑战自我
- python泊松_python实现泊松图像融合
- VSFTP一键部署脚本
- 二代测序原理(Illumina)
- 正则表达式中,表示匹配非数字字符的字符
- 快要做毕设了,几行代码Python生成创意动态二维码,这不猛猛加分......
- js文件上传,java后台接收
- requests-爬取美女图片源码
- application reload
- ip、子网掩码和无类域名路由述说
- 什么是云计算?如何进行云计算安全知多少?
热门文章
- 二零零七年五一节自驾游记(十一)--------0501若尔盖花湖III
- WebGIS开发及二三维GIS开发框架对比分析
- mysql数据迁移到ES
- 如何配置MAC的终端自动补全命令行
- php unzip函数,PHP解压zip文件函数
- 模式识别和机器学习有必要学么_【赠书】快速入门机器学习!最受欢迎AI霸榜书最新版来了!送2本!...
- 【Linux36-2】zabbix监控(mysql+percona+tomcat+主动式监控+onealert云告警)
- [易飞]影响成本码含义与运用
- 买房付尾款要注意的细节
- MMSegmentation跑自己的数据进行二分类