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
What are the kinds of polymorphism?
What is return keyword in java?
Is nullpointerexception checked or unchecked?
What do you mean by compiler?
Difference between collection, collection and collections in java?
What is get () in java?
do I need to use synchronized on setvalue(int)? : Java thread
Can I uninstall java?
What is one third plus one third as a fraction?
Is string pool garbage collected?
What's a method in programming?
What is difference between string and stringbuffer?
How do you take thread dump in java?
What is the same as procedures?
Write a program based on Java script program.