Answer the question
In order to leave comments, you need to log in
Upcast and Downcast?
Help solve this dilemma forever.
Let's say the following code is written in pseudocode:
class A {
}
class B inherit from A {
}
class Program {
public static void Main () {
A first = new A();
B second = new B();
B third = new B();
//1 Upcast or Downcast?
third = first;
//2 Upcast or Downcast?
first = second;
}
}
Answer the question
In order to leave comments, you need to log in
Upcast - casting a child type to a parent type in the inheritance hierarchy.
Downcast - casting a parent type to a child type.
Upcast is always safe, because you can prove at the stage of writing the code that it is legal.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question