java小白,想解决问题
public class kun {public class CPU{
int getSpeed(){
return speed;
}
int speed;
void setSpeed(int m){
speed=m;
}
}
public class HardDisk{
int getAmount(){
return amount;
}
int amount;
void setAmount(int a){
amount=a;
}
}
public class PC{
CPU cpu;
void setCpu(CPU c){
cpu=c;
}
public void show() {
}
}
public static void setHardDisk(HardDisk h){
}
void show(String sudu,String rongliang){
System.out.println(sudu+rongliang);
}
/**
* @Param args
*/
public static void main(String[] args){
CPUcpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk=new HardDisk();
disk.setAmount(200);
PC pc=new PC();
pc.setCPU(CPU c)=cpu;
pc.setHarDisk(HardDisk h)=disk;
pc.show();
}
}
https://s2.232232.xyz/static/4/2022/09/25-632fcaafaeec6.png
这个报错不会解决啊,请大佬指点一下 本帖最后由 big冰 于 2022-9-25 11:47 编辑
pc.setCPU(cpu);
setHarDisk(disk);
set属性的时候错了,应该是这样:
pc.setCPU(pc);
pc.setHarDisk(disk); pc.setCPU(CPU c);
就可以了,不需要加等于号 public class kun {
public static class CPU {
int getSpeed() {
return speed;
}
int speed;
void setSpeed(int m) {
speed = m;
}
}
public static class HardDisk {
int getAmount() {
return amount;
}
int amount;
void setAmount(int a) {
amount = a;
}
}
public static class PC {
CPU cpu;
HardDisk disk;
void setCpu(CPU c) {
cpu = c;
}
public void show() {
}
void setHarDisk(HardDisk disk) {
this.disk = disk;
}
}
public static void setHardDisk(HardDisk h) {
}
void show(String sudu, String rongliang) {
System.out.println(sudu + rongliang);
}
/**
* @Param args
*/
public static void main(String[] args) {
CPU cpu = new CPU();
cpu.setSpeed(2200);
HardDisk disk = new HardDisk();
disk.setAmount(200);
PC pc = new PC();
pc.setCpu(cpu);
pc.setHarDisk(disk);
pc.show();
}
} class CPU{
int getSpeed(){
return speed;
}
int speed;
void setSpeed(int m){
speed=m;
}
}
class HardDisk{
int getAmount(){
return amount;
}
int amount;
void setAmount(int a){
amount=a;
}
}
public class PC{
CPU cpu;
HardDisk harddisk;
void setCpu(CPU c){
cpu=c;
}
void setHardDisk(HardDisk h){
harddisk = h;
}
void show(){
System.out.println("CPU speed:" + cpu.speed + "\nharddisk amount:" + harddisk.amount);
}
public static void main(String[] args){
CPU cpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk=new HardDisk();
disk.setAmount(200);
PC pc=new PC();
pc.setCpu(cpu);
pc.setHardDisk(disk);
pc.show();
}
} pc.setCPU(CPU c)=cpu;
pc.setHarDisk(HardDisk h)=disk;
改:
pc.setCPU(c);
pc.setHarDisk(h); big冰 发表于 2022-9-25 11:43
pc.setCPU(cpu);
setHarDisk(disk);
谢谢大佬,已经解决了 elonlo 发表于 2022-9-25 11:43
set属性的时候错了,应该是这样:
pc.setCPU(pc);
pc.setHarDisk(disk);
谢谢大佬,已经解决了 主骑士 发表于 2022-9-25 11:56
pc.setCPU(CPU c);
就可以了,不需要加等于号
谢谢大佬,已经解决了
页:
[1]
2