package com.imooc; public class Initalphone { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub TelePhone phone=new TelePhone(); TelePhone phone2=new TelePhone(5.0f,1.4f,2.0f); } }
package com.imooc; public class TelePhone { float screen; float cpu; float mem; public TelePhone(){ System.out.println("无参的构造方法"); } public TelePhone(newscreen,newcpu,newmem){ screen=newScreen(); cpu=newcpu; mem=newmem; System.out.println("有参的构造方法"); } }
为什么不行呢?报错呢
变量名要遵循,驼峰原则
public Telephone(newscreen,newcpu,newmem)改为
public Telephone(float newscreen ,float newcpu,float newmem)
还有就是screen=newScreen,你输入的参数是newscreen不是newScreen建议下载一个eclips