问答详情
源自:8-3 如何使用 Java 中的对象

8---12行出现红色提示错误,新手学习求解答,谢谢~

package com.imooc;


public class Telephone {


public static void main(String[] args) {

// TODO Auto-generated method stub

Telephone phone = new Telephone();

phone.sendMessage();

phone.screen = 5.0f;

phone.cpu = 1.4f;

phone.mem = 2.0f;

phone.sendMessage();


}


}


提问者:森女妮萌 2018-01-09 17:19

个回答

  • 亿像
    2018-01-09 17:34:47
    已采纳

    未定义成员变量

    package com.imooc;


    public class Telephone {

    float screen ;

    float cpu ;

    float mem ;

    public void sendMessage(){

    }

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    Telephone phone = new Telephone();

    phone.sendMessage();

    phone.screen = 5.0f;

    phone.cpu = 1.4f;

    phone.mem = 2.0f;

    phone.sendMessage();



    }


    }


  • qq_你好_43
    2018-01-09 17:27:32

    没有定义属性吧,你就直接调方法,给赋值