Java upcasting and Downcasting

                   Upcasting  and Downcasting

  Upcasting






















  • The process of adding a sub-class object to a super-class reference variable is called upcasting.


A  a = new B();


    

Downcasting

  •  The process of getting a sub-class object  placed in a  super 
         
     class variable back to the same sub-class reference is called downcasting
    .

B b = (B) a;


For additional information👇



Comments

Popular posts from this blog

Java Method Overriding

Java Polymorphism

Java Inheritance