Introducing Java Upcasting And Downcasting Concepts
Upcasting And Downcasting
Upcasting
In Casting, it is not possible to access big data from small data. But it is possible to access small data from big data.
Putting something in the Super Class (Object, Variable, Method) in the Sub Class (Object, Variable, Method) is called "Upcasting".
class A {
}
class B extends A {
}
class Test {
A a = new A();
B b = new B();
b = a;
a = b;
}
In Upcasting, what is simply done is to give a Sub Class Object to the Super Class Variable.
Downcasting
Turning the Sub Class Object cast into a Super Class Variable back into a Sub Class Variable is called "Down Casting".
class A {
}
class B extends A {
}
A a = new A();
B b = new B();
A a = new B();
B b = new A();
Downcasting
Comments
Post a Comment