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
State the main difference between c++ and java?
What is public static?
Difference between overriding and overloading in java?
How big is a 64 bit float?
What is a module function?
What is the use of string and stringbuffer?
Is string thread safe in java?
Is call by reference possible in java?
What is appletviewer?
How can you read content from file in java?
What are the kinds of polymorphism?
Can we assign integer value to char in java?
What is compareto () in java?
What is jar?
Why doesn't the java library use a randomized version of quicksort?