为什么编译不过呢?总是提示:The constructor Bus(int, String) is undefined 以下分别为三个类的代码。 package com.imooc; public class Trffic { public int canAc; public String[] style; public Trffic(int newCanAc,String[] newStyle){ canAc = newCanAc; style = newStyle; } public void show(){ System.out.println("Trffic具有运输的能力"); } } package com.imooc; public class Bus extends Trffic { public Bus(int newCanAc,String[] newStyle){ canAc = newCanAc; style = newStyle; } public void show(){ System.out.println("Bus具有"+style+canAc+"个人的能力"); } } package com.imooc; public class Init { public static void main(String[] args) { // TODO Auto-generated method stub Trffic bus = new Bus(40,"陆运"); bus.show(); } }
将String[] 改成String
构造方法参数是数组的,你在new对象的时候也要相对应
Trffic bus = new Bus(40,{"海运"});