基地123 2022-06-05 00:13 采纳率: 90.2%
浏览 36
已结题

找不到符号是什么原因



```java
public class Tester {

    public static void main(String[] args) {
       SimCard a=new SimCard("12345678901");
       SimCard b=new SimCard("12345678902");
       Battery c=new Battery(2000);
       Battery d=new Battery(3000);
       Cellphone f=new Cellphone(a,b,2000);
       System.out.println("card1's number"+a.getNumber());
       System.out.println("card2's number"+b.getNumber());
       System.out.println("card1's capacity"+c.getCapacity());
       System.out.println("card2's capacity"+d.getCapacity());
       Cellphone n=new Cellphone(a,b,3000);
       System.out.println(n.getBatteryCapacity());
        System.out.println("Hello World!");
    }
}
class SimCard{
    private String number;
    public String getNumber(){
        return number;
    }
    public SimCard(String a){
        number=a;
    }
}
class Battery{
    private int capacity=0;
    public int getCapacity(){
        return capacity;
    }
    public Battery(int a){
        capacity=a;
    }
}
class CellPhone{
    private SimCard card1,card2;
    private Battery battery;
    CellPhone(SimCard c1,SimCard c2,Battery bt){
        card1=c1;
        card2=c2;
        battery=bt;
    }
    
    CellPhone(SimCard c1,Battery bt){
        card1=c1;
        battery=bt;
    }
    public void setCard1(SimCard c){
        card1=c;
    }
    public void setCard2(SimCard c){
        card2=c;
    }
    public SimCard getCard1Number(){
        return card1;
    }
    public SimCard getCard2Number(){
        return card2;
    }
    public void setBattery(Battery bt){
        battery=bt;
    }
    public Battery getBattreyCapacity(){
        return battery;
    }
}



```报错如下:Exception in thread "main" java.lang.RuntimeException: Uncompilable code - 找不到符号
符号: 类 Cellphone
位置: 类 com.mycompany.tester.Tester
at com.mycompany.tester.Tester.main(Tester.java:1)
Command execution failed.

  • 写回答

2条回答 默认 最新

  • 白驹_过隙 算法领域新星创作者 2022-06-05 10:44
    关注
    
     
    class SimCard{
        private String number;
        public String getNumber(){
            return number;
        }
        public SimCard(String a){
            number=a;
        }
    }
    class Battery{
        private int capacity=0;
        public int getCapacity(){
            return capacity;
        }
        public Battery(int a){
            capacity=a;
        }
    }
    class CellPhone{
        private SimCard card1,card2;
        private Battery battery;
        CellPhone(SimCard c1,SimCard c2,Battery bt){
            card1=c1;
            card2=c2;
            battery=bt;
        }
        
        CellPhone(SimCard c1,Battery bt){
            card1=c1;
            battery=bt;
        }
        public void setCard1(SimCard c){
            card1=c;
        }
        public void setCard2(SimCard c){
            card2=c;
        }
        public SimCard getCard1Number(){
            return card1;
        }
        public SimCard getCard2Number(){
            return card2;
        }
        public void setBattery(Battery bt){
            battery=bt;
        }
        public Battery getBattreyCapacity(){
            return battery;
        }
    }
    public class Tester {
        public static void main(String[] args) {
           SimCard a=new SimCard("12345678901");
           SimCard b=new SimCard("12345678902");
           Battery c=new Battery(2000);
           Battery d=new Battery(3000);
           CellPhone f=new CellPhone(a,b,c);
           System.out.println("card1's number"+a.getNumber());
           System.out.println("card2's number"+b.getNumber());
           System.out.println("card1's capacity"+c.getCapacity());
           System.out.println("card2's capacity"+d.getCapacity());
           CellPhone n=new CellPhone(a,b,d);
           System.out.println(n.getBattreyCapacity());
           System.out.println("Hello World!");
        }
    }
     
     
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月13日
  • 已采纳回答 6月5日
  • 创建了问题 6月5日

悬赏问题

  • ¥100 python 怎么连接 SQLITE3
  • ¥20 创建taro项目,在vscode上能够写跨平台写微信小程序代码
  • ¥15 网站出现错误跳转问题
  • ¥15 Docker容器里已经安装了ssh,但打包迁移到新机器一直容器一直提示unrecognized service。
  • ¥15 综合布线实例设计,就好看好看不恐怖可好滤镜好聚
  • ¥15 使用moviepy库视频合并时出错
  • ¥30 FLUENT液固传质UDF
  • ¥15 怎么看梯度直方图以,怎么判断梯度消失/爆炸,怎么解决
  • ¥15 aspnetdll文件访问拒绝
  • ¥15 wpf中在模版中寻找元素