Downcasting: Downcasting का मतलब है कि किसी child object में parent object का typecasting । Downcasting को clarified नहीं किया जा सकता है।
Downcasting का use upcasting की तुलना में अधिक बार किया जाता है। जब हम किसी subtype के Specific practices तक पहुँचना चाहते हैं, तो downcasting का उपयोग करें।
जब भी हम subtypes के behavior को access करना चाहते हैं, तो हम downcasting का use करते हैं। यह अधिक से अधिक use किया जाता है upcasting की तुलना में।
Following image upcasting and downcasting के concept को दर्शाती है:
Example:
public class One { void show() { System.out.println("show method in class One"); } } public class Two extends One { void wow() { System.out.println("wow method in class Two"); } } public class Test { public static void main(String[] args) { One o = new Two(); Two t = (Two)o; //Downcasting t.wow(); } }