//这是我的定义的类
package com.imooc;
public class FangFa {
private float screen;
private float cpu;
private float mem;
public float getScreen(){
return screen;
}
public void setScreen(float newScreen){
screen=newScreen;
}
public FangFa(){
System.out.println("无参的构造方法执行了!");
}
public FangFa(float newScreen,float newCpu,float newMem){
screen=newScreen;
cpu=newCpu;
mem=newMem;
System.out.println("有参的构造方法执行了!");
}
}
//这是主函数
package com.imooc;
public class FZ {
public static void main(String[] args) {
// TODO Auto-generated method stub
FangFa hello=new FangFa();
FangFa hi=new FangFa(5.0f,1f,2.0f);
}
hi.setScreen(6.0f);
System.out.println("screen:"+hi.getScreen());
}
然后有一个错误不知道怎么改了
hi.setScreen(6.0f);
System.out.println("screen:"+hi.getScreen());
写到main方法里
main方法的大括号结束位置不对。
FangFa hi=new FangFa(5.0f,1f,2.0f);里没有错误么
FangFa hi=new FangFa(5.0f,1.0f,2.0f);
客气了,加油!