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?

Answers were Sorted based on User's Feedback



what are upcasting and downcasting?..

Answer / arjun kumar

When we cast a reference along the class hierarchy in a
direction from the sub classes towards the root, it is an
upcast.
When we cast a reference along the class hierarchy in a
direction from the root class towards the children or
subclasses, it is downcast.

Is This Answer Correct ?    19 Yes 3 No

what are upcasting and downcasting?..

Answer / 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

what are upcasting and downcasting?..

Answer / vikram aditya

When reference variable of super class refers to the object of sub class that mechanism is known as Up-casting.
Ex:
A a=new B();

When reference variable of sub class refers to the object of super class that mechanism is known as Down-casting.
Ex:
B b=(B) a;

//Where A is super class and B is subclass
 

Is This Answer Correct ?    6 Yes 0 No

what are upcasting and downcasting?..

Answer / malligontla

A super class reference can be converted into a subclass
reference but this subclass reference is not useful to call
the methods of any of the classes. This convention is known
as Downcasting.

We can convert the subclass reference to a superclass
reference without using the cast operation, because compiler
will internally take care of the casting. This is known as
Upcasting.

Is This Answer Correct ?    3 Yes 2 No

what are upcasting and downcasting?..

Answer / amandee[

when we cast reference variable into subclass then
implicitly casting happens means that up casting and vice versa

Is This Answer Correct ?    1 Yes 9 No

Post New Answer

More Core Java Interview Questions

When will we prefer to use set and list in java and why?

0 Answers  


why are wait(), notify() and notifyall() methods defined in the object class? : Java thread

0 Answers  


How do you pass by reference?

0 Answers  


what is finalmethod & final variable with example?

6 Answers   HP,


What is command line used for?

0 Answers  


What is Collection interface?

1 Answers   Zensar,


What is object english?

0 Answers  


In java how do we copy objects?

0 Answers  


Java openings 3 - 5 years, Lnt Infotech. requirements - core java, J2ee, struts, hibernate Interview Date:- 19 March 2011 Time:- 9:00 AM to 12:00 Pm Interview Location - L & T Infotech, Manapakkam, Chennai Refererral PS NO:- 291649 (Please mention this when u fill the form only then u will be considered for interview) Documents Required:- Latest Resume, Photograph and last 3 payslips Mail me on vasan2211@gmail.com once u appear for interview

0 Answers   L&T,


Explain about complier design(phases)

0 Answers   Aditi Placement Service,


Can an unreachable object become reachable again?

3 Answers  


is it possible to add a object in a HASHMAP

6 Answers   HCL,


Categories