Is it possible to do the following - allowing for a properly coded constructor:
object1.method(new objectType1(argument1, argument2));
Here, object1 contains objects of objectType2.
So, consider the following code:
portfolio.addInvestment(new StockInvestment(stock, numshares));
addInvestment adds an object of type StockInvestment to an ArrayList . So, addInvestment receives an object of type StockInvestment
是的,这在 Java 中是完全正常的
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.