这是我的程序:
abstract class Contents
{
abstract public int value();
}
interface Destination
{
String readLabel();
}
public class Parcel3
{
class PContents extends Contents
{
private int i=11;
public int value()
{
return i;
}
}
public Contents count()
{
return new PContents();
}
protected class PDestination implements Destination
{
private String La;
private PDestination(String w)
{
La=w;
}
public String readLabel()
{
return La;
}
}
}
class Ex
{
public static void main(String args[])
{
Parcel3 p=new Parcel3();
Contents c=p.count();
System.out.println("c.value is"+c.value());
}
}
文件名是Parcel3.java,这个程序不能运行,但是把主函数放到上面的parcel类中就能运行,
请高手解释一下这是问什么?谢谢
我还有一个问题就是关于java函数中对象类型的参数的传递的问题,到底是传递的是“引用”,还是传值?还是都有....
(简单类型的参数当然是传参数,我倒是知道....)
abstract class Contents
{
abstract public int value();
}
interface Destination
{
String readLabel();
}
public class Parcel3
{
class PContents extends Contents
{
private int i=11;
public int value()
{
return i;
}
}
public Contents count()
{
return new PContents();
}
protected class PDestination implements Destination
{
private String La;
private PDestination(String w)
{
La=w;
}
public String readLabel()
{
return La;
}
}
}
class Ex
{
public static void main(String args[])
{
Parcel3 p=new Parcel3();
Contents c=p.count();
System.out.println("c.value is"+c.value());
}
}
文件名是Parcel3.java,这个程序不能运行,但是把主函数放到上面的parcel类中就能运行,
请高手解释一下这是问什么?谢谢
我还有一个问题就是关于java函数中对象类型的参数的传递的问题,到底是传递的是“引用”,还是传值?还是都有....
(简单类型的参数当然是传参数,我倒是知道....)
对象的传递是按引用传递,传的是地址
{
abstract public int value();
}
interface Destination
{
String readLabel();
}
public class abcde
{
class PContents extends Contents
{
private int i=11;
public int value()
{
return i;
}
}
public Contents count()
{
return new PContents();
}
protected class PDestination implements Destination
{
private String La;
private PDestination(String w)
{
La=w;
}
public String readLabel()
{
return La;
}
}
}
class Ex
{
public static void main(String args[])
{
abcde p=new abcde();
Contents c=p.count();
System.out.println("c.value is "+c.value());
}
}
这样就好了结果是c.value is 11
刚才调试给改了。。