定义抽象类后,子类必须实现抽象类里面的方法,但是如果子类还有另外的变量时,这个变量是如何调用的??编辑后一直提醒错误,提示抽象类里没有这个变量
Vehicle.java
package rentcar.com.imooc; public abstract class Vehicle { public int orderNum; public String carName; public int rentMoney; }
Audi4.java
package rentcar.com.imooc; public class Audi4 extends Vehicle { Audi4(){ orderNum= 1; carName="奥迪A4"; rentMoney=500; } int zrnum=4; }
rentcarmain.java
package rentcar.com.imooc; import java.util.Scanner; public class rentcarmain { public static void main(String[] args) { // TODO Auto-generated method stub rentcarmain hello=new rentcarmain(); System.out.println("欢迎使用答答租车系统"); System.out.println("您是否要租车:1、是(进入系统),2、否(退出系统)"); Scanner input1=new Scanner(System.in); int enter1=input1.nextInt(); hello.menuInOrOut(enter1); } public void menuInOrOut(int enter){ Vehicle veh1=new Audi4(); Vehicle veh2=new mazada6(); Vehicle veh3=new pikashow6(); Vehicle veh4=new GoldDragron(); Vehicle veh5=new SongHuaJiang(); Vehicle veh6=new YiWeiKe(); if(enter==1){ System.out.println("本公司可租的车类型及价目表:"); System.out.println(veh1.orderNum+"\t"+veh1.carName+"\t"+veh1.rentMoney+"\t"); } } }
应该如何在rentcarname里面调用子类Audi4里的这个zrnum=4变量呢?