Hi ,I have super class vehicle,truck extends vehicle,and I created array in test class full with objects from vehicle and truck,how can I call method from vehicle,is this the way
(truck)object1[1].getMethod()
Recommended Answers
Jump to Postdata[2].getLoadCap();
should be
((Truck)data[2]).getLoadCap();
as already explained.
And of course ideally you'd handle errors doing the casting.
All 3 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.