Is it possible to return the return type of a method as an object that is not in the class you are creating the method in? for example, I have a Person class and within it I want to create a Method whose return type is a Car, if possible, what is that called?
example:
public Car newCar(){
}
this inside a Person class
3
Ya, you can return any type as long as said type exists in the code base. In the case of your example car. As long as there is the class that creates said new type then you can create a return method for the type.
Creating an object (This will allow you to create a new type to return): https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html
Returning a type: https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html