读书人

急 问个关于命令行下运行java程序的有

发布时间: 2012-01-23 21:57:28 作者: rapoo

急急急 问个关于命令行下运行java程序的问题?
为什么我的程序在eclipse下可以运行
而在命令行下却不能运行呢
编译都不通过
这是什么原因?谢谢


源程序
1.

package lala;

public class Computer {

/**
* Computer Class
*/
protected String PC_name; //属性 名字
protected String pc_color; //.. 颜色
protected String pc_type; //.. 型号
protected int pc_ram; //内存容量
protected int pc_harddisk; //硬盘容量
protected float pc_price; //价格

protected int pc_state=0; // 工作状态 0为 停止 1 运行 -1 挂起



Computer(){ //无参的构造函数,什么都不做

}

public Computer(String myname,String mycolor,String mytype,int myram,int myhard,float myprice) //带参数的构造函数
{
this.PC_name=myname;
this.pc_color=mycolor;
this.pc_type=mytype;
this.pc_ram=myram;
this.pc_harddisk=myhard;
this.pc_price=myprice;
}


public void pc_open(){ //打开方法
pc_state=1;
}
public void pc_close(){ //关闭方法
pc_state=0;
}
public void pc_hitch(){ //挂其方法
pc_state=-1;
}

public void set(String myname,String mycolor,String mytype,int myram,int myhard,float myprice){ //set方法,设置各属性值
this.PC_name=myname;
this.pc_color=mycolor;
this.pc_type=mytype;
this.pc_ram=myram;
this.pc_harddisk=myhard;
this.pc_price=myprice;
}

public void setcolor(String str){ //本类的方法,其它类似
this.pc_color=str;
}
public void getcolor(){
System.out.println( "颜色: "+pc_color);
}
public void get(){ //get方法输出各字短值
System.out.println( "品牌: "+PC_name);
System.out.println( "颜色: "+pc_color);
System.out.println( "CPU型号: "+pc_type);
System.out.println( "内存: "+pc_ram);
System.out.println( "硬盘: "+pc_harddisk);
System.out.println( "价格: "+pc_price);
System.out.println( "工作状态: "+pc_state);
}
}

这是父类


2.
package lala;

public class BookComputer extends Computer {

/**
* 笔记本class
* by hip 07/7/9
*/
private float Bookpc_long; //机箱长度
private float Bookpc_width;//机箱宽度
private float Bookpc_thick;//机向后度
private float Bookpc_weight;//机葙重量
private boolean Bookpc_cellstate=false;//电池状态 注: false为不工作状态,true为电池工作状态;莫认为0

BookComputer(){ //默认的无参构造函数

}
public BookComputer(String myname,String mycolor,String mytype,int myram,int myhard,float myprice,float mylong,float mywidth,float mythick,float myweight){ //带参数的构造函数


this.PC_name=myname;
this.pc_color=mycolor;
this.pc_type=mytype;
this.pc_ram=myram;
this.pc_harddisk=myhard;
this.pc_price=myprice;
this.Bookpc_long=mylong;
this.Bookpc_width=mywidth;
this.Bookpc_thick=mythick;
this.Bookpc_weight=myweight;
}


public void bookpc_cellpost(){
if(pc_state==-1){

Bookpc_cellstate=true; //如果工作状态为挂起,则为断电,这时激发电池工作状态
}
else
{
Bookpc_cellstate=false;
}
System.out.println( "电池状态: "+Bookpc_cellstate);
}
public void set(String myname,String mycolor,String mytype,int myram,int myhard,float myprice,float mylong,float mywidth,float mythick,float myweight){
PC_name=myname;
pc_color=mycolor;
pc_type=mytype;
pc_ram=myram;
pc_harddisk=myhard;
pc_price=myprice;
Bookpc_long=mylong;
Bookpc_width=mywidth;
Bookpc_thick=mythick;
Bookpc_weight=myweight;

}
public void setname(String str){ //子类定义的自己方法,初始化属性的函数其它类似,不一一举例
this.PC_name=str;
}

public void get(){
System.out.println( "品牌: "+PC_name);
System.out.println( "颜色: "+pc_color);
System.out.println( "CPU型号: "+pc_type);
System.out.println( "内存: "+pc_ram);
System.out.println( "硬盘: "+pc_harddisk);
System.out.println( "价格: "+pc_price);
System.out.println( "工作状态: "+pc_state);
System.out.println( "机箱长度: "+Bookpc_long);
System.out.println( "机箱宽度: "+Bookpc_width);
System.out.println( "机箱厚度: "+Bookpc_thick);
System.out.println( "重量: "+Bookpc_weight);
}

public static void main(String[] args){
BookComputer f=new BookComputer();
f.set( "snail ", "red ", "small snail ", 1000, 80, 4000, 800,100, 20,30);
f.setname( "小豆包 "); //调用自己本类的方法
f.get();
f.getcolor(); //调用父类中的反法
f.pc_hitch();//调用父类中的挂起方法
f.bookpc_cellpost(); //子类调用自己的方法
}
}


这是子类
为什么编译这个就出错了呢?


[解决办法]
把上面的package lala去掉。

读书人网 >J2SE开发

热点推荐