以下代碼是分在三個(gè)class文件的。貼到一起//創(chuàng)建一個(gè)Vehicle的父類public class Vehicle {int paasenger;}//創(chuàng)建一個(gè)Car的子類public class Car extends Vehicle {int passenger = 4;}//執(zhí)行public class initial {public static void main(String[] args) {Vehicle obj1 = new Car();System.out.println(obj1.passenger);}}結(jié)果是4
為什么運(yùn)行的結(jié)果是 0 而不是 4?
huangguayutou
2016-04-30 19:38:40