Casting Objects in Java


Object casting allows you to convert an object of one type into another.

Source Code

class Animal {}
class Dog extends Animal {
    public static void main(String[] args) {
        Animal myDog = new Dog();
        Dog dog = (Dog) myDog; // Casting
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments