What happens when you try to compile / run the following code:

abstract class Animal {
    static {
        System.out.println("Inside Animal");
    }
}

class Cat extends Animal {
    static {
        System.out.println("Inside Cat");
    }
}

class Dog extends Animal {
    static {
        System.out.println("Inside Dog");
    }
}

public class Main {
     public static void main(String[] args){
          Animal cat = new Cat();
          Animal dog = new Dog();
     }
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes