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
Define interface in java?
What is data structure in java?
What are the topics in advance java?
what is method reference in java 8?
In which order the iterator iterates over collection?
Why javac is not recognized?
What is the difference between == and === javascript?
What are the drawbacks of reflection?
How to handle a web browser resize operation?
How is the marker interface used in Java?
What is main method?
What does a method signature consist of?
What is the difference between multiple processes and multiple threads?
Can we write method inside a method in java?
Is arraylist a class in java?