r/learnjava • u/Jacksontryan21 • Nov 22 '25
Casting
I was going over assignments from a past java class and in one of our assignments, we implemented the Clonable interface and got this method:
public Ellipse clone(){
try{
return (Ellipse)super.clone();
}catch(CloneNotSupportedException Ex){
Ex.printStackTrace();
}
}
I was wondering how the line return (Ellipse)super.clone(); works. I understand that super.clone() returns an object, but how does that object get turned into an Ellipse?
3
Upvotes
View all comments
Show parent comment
1
u/Jacksontryan21 Nov 22 '25
How does that Object get turned into an Ellipse though? I understand what this line does, I just don't understand how the compiler works to get the Object turned into an Ellipse when casted to an Ellipse