Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

In this case:
TypeA objA = new TypeB();

I said:
TypeB class has to be a super class of TypeA in order to create a object that is TypeA from TypeB.
Am I correct?

asked in CSC305 Fall 2022 by (1 point)

2 Answers

+10 votes

TypeA can also be an interface that TypeB implements. e.g.

List myList = new ArrayList();

Also, TypeA could be a superclass of a superclass of TypeB, etc.

answered by (3.5k points)
+2

Or could TypeA be an abstract class which TypeB is a subclass of?

+9 votes

I think it's for interfaces though, like for instance:

List names = new ArrayList<>();

answered by (1 point)
...