I'm trying to understand how object casting works in Java Internally.
Here is my small code example
public interface Processor {
}
public class Mainclass {
Object getObject(){
return new Object();
}
public static void main(String[] args){
Mainclass ob = new Mainclass();
Processor prcsr = (Processor) ob.getObject();
}
}
When ob.getObject()
gets called, It returns an Object
reference type which is holding a location of Object
class instance. Correct ?
So when we cast Object
reference type to Processor
, What is happening actually ? Does it converts Object
reference type to processor type which will be holding to Object
class Instance location?
If yes, then Processor is a Interface here, then who is Implementing this Interface here ?
I'm confused here, Can anyone help me how it works internally ?
Thanks