当前位置: 技术问答>java相关
为啥这段代码可以编译却不能执行? (急)
来源: 互联网 发布时间:2015-03-31
本文导语: //: Parcel3.java //abstract class Contents{ interface Contents{ abstract public int value(); } interface Destination{ String readLabel(); } public class Parcel3{ private class PContents implements Contents{ private int i=11; public int value(){return ...
//: Parcel3.java
//abstract class Contents{
interface Contents{
abstract public int value();
}
interface Destination{
String readLabel();
}
public class Parcel3{
private class PContents implements Contents{
private int i=11;
public int value(){return i;}
}
protected class PDestination implements Destination{
private String Label;
private PDestination(String whereto){
Label=whereto;
}
public String readLabel(){return Label;}
}
public Destination dest(String s){
return new PDestination(s);
}
public Contents cont(){
return new PContents();
}
}
class Test{
public static void main(String args[]){
Parcel3 p=new Parcel3();
Contents c=p.cont();
Destination d=p.dest("Sailing");
}
}
//abstract class Contents{
interface Contents{
abstract public int value();
}
interface Destination{
String readLabel();
}
public class Parcel3{
private class PContents implements Contents{
private int i=11;
public int value(){return i;}
}
protected class PDestination implements Destination{
private String Label;
private PDestination(String whereto){
Label=whereto;
}
public String readLabel(){return Label;}
}
public Destination dest(String s){
return new PDestination(s);
}
public Contents cont(){
return new PContents();
}
}
class Test{
public static void main(String args[]){
Parcel3 p=new Parcel3();
Contents c=p.cont();
Destination d=p.dest("Sailing");
}
}
|
可以呀..只是你没有把结果打印出来:
class Test{
public static void main(String args[]){
Parcel3 p=new Parcel3();
Contents c=p.cont();
Destination d=p.dest("Sailing");
System.out.println(d.readLabel());//加上这行..
}
}
class Test{
public static void main(String args[]){
Parcel3 p=new Parcel3();
Contents c=p.cont();
Destination d=p.dest("Sailing");
System.out.println(d.readLabel());//加上这行..
}
}
|
你把class Test写到Test.java中,编译这两个类就可以了。