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

What are the kinds of polymorphism?

1071


What is return keyword in java?

1042


Is nullpointerexception checked or unchecked?

1011


What do you mean by compiler?

1026


Difference between collection, collection and collections in java?

992


What is get () in java?

1012


do I need to use synchronized on setvalue(int)? : Java thread

992


Can I uninstall java?

1023


What is one third plus one third as a fraction?

914


Is string pool garbage collected?

981


What's a method in programming?

1046


What is difference between string and stringbuffer?

1065


How do you take thread dump in java?

975


What is the same as procedures?

961


Write a program based on Java script program.

1116