您的位置首页百科问答

JAVA中的((TestA) new TestB())是什么意思?

JAVA中的((TestA) new TestB())是什么意思?

这是Java中的类型强制转换。

new TestB()是返回了TestB对象实例,然后再强制转换为TestA,除了类之间的强制转换之外,还有String、Integer、Float等等。

Java中要实现类型转换,必需要有继承关系,在这里,B是子类,A是父类,B继承A。