以下代码输出为:(numberOfInstances)
class Parent
{
public int numberOfInstances;
protected Parent(int numberOfInstance)
{
this.numberOfInstances=numberOfInstance;
}
}public class Example extends Parent
{
private Example(int numberOfInstances)
{
super(numberOfInstances);
}
public static void main(String...strings)
{
Example ext=new Example(420);
System.out.println(ext.numberOfInstances);
}
}
class Parent
{
public int numberOfInstances;
protected Parent(int numberOfInstance)
{
this.numberOfInstances=numberOfInstance;
}
}public class Example extends Parent
{
private Example(int numberOfInstances)
{
super(numberOfInstances);
}
public static void main(String...strings)
{
Example ext=new Example(420);
System.out.println(ext.numberOfInstances);
}
}
解决方案 »
- 单核有线程同步吗 多核肯定有线程同步吧 详细一点 谢谢
- 如何把Eclipse C++和eclipse java两个IDE集成到一起?
- 新手:子类和超类
- JAVA Web编程中Oracle SQL的调优及表、索引的设计和优化
- java 1.5中 装箱 取消装箱 加宽 是什么意思 ? 能解释一下么?
- 谁有用年nio写的客户端和服务器端来进行多人通讯的例子?
- 散人!本人急需visual j++开发软件
- 人气好像不是很旺呀!放点分,给大家送礼啦~
- 用jbuilder编写一个扫雷的程序.(在线等待)
- 怎样才能去掉Applet中左下角的“Java Applet Window"字样?
- 类的加载
- ByteArrayOutputStream的toByteArray();方法
Example 的构造器是私有的,在类的外部无法调用(外面调用报错),但是main方法在类的内部可以访问到。Example继承了Parent的numberOfInstances属性,构造器引用父类构造器进行赋值。