基地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日

悬赏问题

  • ¥15 sqpingboot在父模块已经引入了mybatisplus 在子组件不写版本号还是报错
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么
  • ¥15 Linux下安装搜狗拼音不能显示中文
  • ¥15 事件7000导致的自动重启如何解决
  • ¥15 (标签-matlab|关键词-m3)
  • ¥20 做一个web书店,带答辩
  • ¥15 #求带 python,使用pycharm爬取智联招聘数据资源并保存为Excel文件,同时以图表形式呈现