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

Define interface in java?

1087


What is data structure in java?

996


What are the topics in advance java?

970


what is method reference in java 8?

1040


In which order the iterator iterates over collection?

996


Why javac is not recognized?

943


What is the difference between == and === javascript?

1188


What are the drawbacks of reflection?

1017


How to handle a web browser resize operation?

1077


How is the marker interface used in Java?

1101


What is main method?

1043


What does a method signature consist of?

985


What is the difference between multiple processes and multiple threads?

1213


Can we write method inside a method in java?

998


Is arraylist a class in java?

1070