Total members 10261 | Gratitudes |It is currently Wed May 23, 2012 8:13 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: difference between upcasting and downcasting
PostPosted: Mon Aug 08, 2011 8:26 pm 

what is the difference between up-casting and down-casting


TOP
  
Reply with quote  
 Question subject: Re: difference between upcasting and downcasting
PostPosted: Wed Aug 10, 2011 2:27 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
Code:


 
public class ExampleClass {

    public static 
void main(String[] args) {

        
// Upcasting from subclass to super class.
        
A aRef=new C();

        
aRef.display();//Am in class C
        //Downcasting of reference to subclass reference.
        
B bRef=(BaRef;
        
bRef.display();//Am in class C

        // Note the display function of class C is called because the type of object is class C

    
}
}

interface 

{
  
void display();
}

class 
implements A
{

    public 
void display() {
        
System.out.println("Am in class B");
    }

}

class 
extends B
{
    @
Override
    
public void display() {
        
System.out.println("Am in class C");
    }
}

 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 find the difference between dates in asp.net
 Difference between PHP echo() and PHP print()?
 Difference between forward and sendRedirect
 The difference between an Interface and an Abstract class
 difference between a while statement and a do statement
 difference between a Window and a Frame
 difference between the String and StringBuffer
 difference between a static and a non-static inner class
 difference between break statement and a continue statement
 difference between the Boolean & operator and the &&

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google [Bot] and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team