Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what are upcasting and downcasting?

Answer Posted / aravind

Please find the difference between DownCasting and Upcasting
with the beloe example

Base Class is Shape

public class Shape
{
protected int m_xpos;
protected int m_ypos;
public Shape()
{
}
public Shape(int x, int y)
{
m_xpos = x;
m_ypos = y;
}
}

Circle class which extends Shape class

public class Circle extends Shape
{
public Circle()
{
}
public Circle(int x, int y)
{
}
}


Main Class:

class CastingExample{
public static void main(String[] args) {
Shape s = new Circle(); // Upcasting
Circle c;
c = (Circle)s; // Downcasting explicitly we have to
do,this is unsafe.
}
}

Is This Answer Correct ?    10 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is bigger float or double?

918


What are the different ways to handle exceptions?

938


What is garbage collection? What is the process that is responsible for doing that in java?

1054


What is an immutable class? How to create an immutable class?

997


Define Multiprogramming and Multiprocessing in java.

1061


You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain

926


What is a singleton in genetics?

999


why are there separate wait and sleep methods? : Java thread

973


What is the difference between assignment and initialization?

993


What is a java applet? What is an interface?

1028


What is the difference between a factory and abstract factory pattern?

1082


How to call one constructor from the other constructor ?

983


What do you know about the garbage collector in java?

1034


What is array size in java?

915


Explain the difference between static and dynamic binding in java?

1016