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 is the difference between object oriented programming language and object based programming language?
Which collections are thread safe in java?
What does a method signature consist of?
What is %d in printf?
Is vector synchronized in java?
What do you understand by overloading and overriding in java?
What does pointer mean?
How do you change an int to a string?
Differentiate between class and structure.
Difference between a class and an object?
What are the differences between getting and load method?
What is variable in java?
What is the function of compareto in java?
Is it possible to use Semaphore/ Mutex in an Interrupt Handler?
Can memory leak in java?