Tuesday, March 25, 2025
What is Downcasting?

 

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 को दर्शाती है:

what ins downcasting

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();  
   } 
 }
My name is Yash Pogra and I am the chief blogger at Codeash and where I like to share my internet/tech experience with my online readers on this website. I have been a webmaster from 2015 which is when I had registered my first company by the name Codeash. I have ventured into different online businesses like offering SEO Services, Digital Marketing and website development services.

Related Article

No Related Article

0 Comments

Leave a Comment