哎呦-_-不错 2022-04-07 17:08 采纳率: 100%
浏览 32
已结题

同一个包中有Handset类,请问Handset handset; 这一步是什么意思?我以为是新建对象,可是new不出Handset

package com.mashibing.interfaceDemo3;

import java.util.Scanner;

/**

  • 装配手机类

  • /
    public class Host {
    Scanner sc=new Scanner(System.in);

    int brandId,typeId;//手机品牌 手机型号

    public Handset select(int type){

      Handset handset;    // 
      if(type==1){
          //实现智能手机功能
          handset = new AptitudeHandset();
          System.out.println("1、小米 2、华为、 3、苹果");
          System.out.println("请选择手机品牌:");
          brandId=sc.nextInt();
          switch (brandId){
              case 1:
                  //设置手机品牌
                  handset.setBrand("小米");
                  // System.out.println(aptitudeHandset.getBrand());
                  System.out.println("1、红米 2、小米note 3、小米8");
                  System.out.println("请选择小米手机类型");
                  typeId=sc.nextInt();
                  //设置小米手机类型
                  if(typeId==1){
                      handset.setType("红米");
                  }else if (typeId==2){
                      handset.setType("小米note");
                  }else {
                      handset.setType("小米8");
                  }
                  break;
              case 2:
                  handset.setBrand("华为");
                  System.out.println("1、荣耀  2、nava  3、华为10");
                  System.out.println("请选择华为手机类型");
                  typeId=sc.nextInt();
                  //设置小米手机类型
                  if(typeId==1){
                      handset.setType("荣耀 ");
                  }else if (typeId==2){
                      handset.setType("nava");
                  }else {
                      handset.setType("华为10");
                  }
                  break;
              default:
                  handset.setBrand("苹果");
                  System.out.println("1、iphone7  2、iphoneX  3、iphone9");
                  System.out.println("请选择华为手机类型");
                  typeId=sc.nextInt();
                  //设置小米手机类型
                  if(typeId==1){
                      handset.setType("iphone7 ");
                  }else if (typeId==2){
                      handset.setType("iphoneX");
                  }else {
                      handset.setType("iphone9");
                  }
                  break;
          }
      }else{
          //实现普通手机功能
          handset=new CommonHandset();
          System.out.println("1、诺基亚 2、金立手机 3、三星");
          System.out.println("请选择普通手机品牌");
          brandId=sc.nextInt();
          switch (brandId){
              case 1:
                  //设置手机品牌
                  handset.setBrand("诺基亚");
                  System.out.println("1、210黑色直板 2、105老人备用机 3、3.1plus移动版");
                  System.out.println("请选择诺基亚手机类型");
                  typeId=sc.nextInt();
                  if (typeId==1){
                      handset.setType("210黑色直板");
                  }else if(typeId==2){
                      handset.setType("105老人备用机");
                  }else {
                      handset.setType("3.1plus移动版");
                  }
                  break;
              case 2:
                  handset.setBrand("金立");
                  System.out.println("1、语音王 2、A350");
                  System.out.println("请选择金立手机类型");
                  typeId=sc.nextInt();
                  if(typeId==1){
                      handset.setType("语音王");
                  }else {
                      handset.setType("A350");
                  }
                  break;
              default:
                  handset.setBrand("三星");
                  System.out.println("1、B289电信 2、E1150老人机");
                  System.out.println("请选择三星手机类型");
                  typeId=sc.nextInt();
                  if(typeId==1){
                      handset.setType("B289电信");
                  }else {
                      handset.setType("E1150老人机");
                  }
                  break;
          }
    
      }
      return  handset;
    

    }
    }

  • 写回答

2条回答 默认 最新

  • Roc-xb 后端领域优质创作者 2022-04-07 17:16
    关注

    Handset handset; 就是定义一个手机对象。
    初始化的话,你可以用:
    Handset handset=new AptitudeHandset(); //创建智能手机对象
    Handset handset=new CommonHandset(); //创建普通手机对象
    Handset 是AptitudeHandset的父类。
    Handset是CommonHandset()的父类。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月15日
  • 已采纳回答 4月7日
  • 创建了问题 4月7日

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大