哎呦-_-不错 2022-04-07 09: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 09:16
    关注

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

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

报告相同问题?

问题事件

  • 系统已结题 4月14日
  • 已采纳回答 4月7日
  • 创建了问题 4月7日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部