upcasting and downcasting examples. Some commonly used default string method. (JAVA)
Answers
Answered by
1
Down casting
Animal animal = new Dog();
Dog dog = (Dog) animal;
here animal is a higher variable type and dog is lower. Then we down casting animal as Dog type in second line.
Up casting will be opposite ...
Circle circ = new Circle();
Shape shape = (Shape) circ;
Animal animal = new Dog();
Dog dog = (Dog) animal;
here animal is a higher variable type and dog is lower. Then we down casting animal as Dog type in second line.
Up casting will be opposite ...
Circle circ = new Circle();
Shape shape = (Shape) circ;
Similar questions