m0_67493752 2022-04-26 12:12 采纳率: 37.5%
浏览 51
已结题

Java面向对象基础编程

img

img


怎样改变才不是空值,标红的地方怎么改都是标红,添加了参数还是会报错,求问

  • 写回答

4条回答 默认 最新

  • 不甘_ 2022-04-26 16:24
    关注

    将题主的代码写了一点,题主可以作为参考,望采纳

    
    public class Clock {
        //你的参数
        String structure;
        String style;
        double price;
        String time;
        //无参构造
        public Clock() {
        }
        //全参构造
        public Clock(String structure, String style, double price, String time) {
            this.structure = structure;
            this.style = style;
            this.price = price;
            this.time = time;
        }
        //以下为全部参数的get和set方法
        public String getStructure() {
            return structure;
        }
        
        public void setStructure(String structure) {
            this.structure = structure;
        }
        
        public String getStyle() {
            return style;
        }
        
        public void setStyle(String style) {
            this.style = style;
        }
        
        public double getPrice() {
            return price;
        }
        
        public void setPrice(double price) {
            this.price = price;
        }
        
        public String getTime() {
            return time;
        }
        
        public void setTime(String time) {
            this.time = time;
        }
        
        public static void main(String[] args) {
            //创建对象
            Clock clock=new Clock();
    //    没有给structure设置值    打印为空
            System.out.println(clock.structure);
    //        给structure设置值,打印“我是structure”
            clock.setStructure("我是structure");
            System.out.println(clock.structure);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号